@unbrained/pm-cli 2026.8.10 → 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 (175) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/CHANGELOG.md +102 -80
  3. package/dist/cli/commander-usage.js +79 -7
  4. package/dist/cli/error-guidance.d.ts +10 -0
  5. package/dist/cli/error-guidance.js +76 -25
  6. package/dist/cli/main.js +6 -2
  7. package/dist/cli/register-assurance.d.ts +8 -0
  8. package/dist/cli/register-assurance.js +52 -0
  9. package/dist/cli/register-files-lookup.js +14 -3
  10. package/dist/cli/register-mutation.js +30 -9
  11. package/dist/cli/register-operations.js +16 -11
  12. package/dist/cli-bundle/bundle-manifest.json +159 -159
  13. package/dist/cli-bundle/chunks/{chunk-TRWXF476.js → chunk-2OOU2AFH.js} +2 -2
  14. package/dist/cli-bundle/chunks/chunk-2RA2YTHJ.js +33 -0
  15. package/dist/cli-bundle/chunks/chunk-A2SJGHSI.js +3 -0
  16. package/dist/cli-bundle/chunks/chunk-DSKYD4LG.js +13 -0
  17. package/dist/cli-bundle/chunks/chunk-HC3GM6YY.js +194 -0
  18. package/dist/cli-bundle/chunks/chunk-IUNRVDAI.js +2 -0
  19. package/dist/cli-bundle/chunks/chunk-W7CPZGSB.js +2 -0
  20. package/dist/cli-bundle/chunks/{chunk-EBO7OUUE.js → chunk-WMEZHCFI.js} +59 -53
  21. package/dist/cli-bundle/chunks/{chunk-ETML5C6H.js → chunk-ZU34C3LH.js} +47 -47
  22. package/dist/cli-bundle/chunks/chunk-ZXOC6HG5.js +5 -0
  23. package/dist/cli-bundle/chunks/{register-list-query-OJ6ZXKV4.js → register-list-query-HAUXVUPY.js} +8 -8
  24. package/dist/cli-bundle/chunks/register-mutation-7Y5U7ABT.js +20 -0
  25. package/dist/cli-bundle/chunks/register-operations-EQX3DLAZ.js +2 -0
  26. package/dist/cli-bundle/chunks/{register-setup-S3KT2LTH.js → register-setup-NOCOOWQY.js} +2 -2
  27. package/dist/cli-bundle/focused-chunks/{chunk-34SX654S.js → chunk-23FTGO3W.js} +2 -2
  28. package/dist/cli-bundle/focused-chunks/{chunk-2COZ67XT.js → chunk-2DL3MRTD.js} +2 -2
  29. package/dist/cli-bundle/focused-chunks/chunk-3AYKXMYX.js +2 -0
  30. package/dist/cli-bundle/focused-chunks/chunk-4AHEC74N.js +2 -0
  31. package/dist/cli-bundle/focused-chunks/{chunk-7UN6BHHO.js → chunk-4H5IA6AV.js} +2 -2
  32. package/dist/cli-bundle/focused-chunks/chunk-4SV3ZKG3.js +16 -0
  33. package/dist/cli-bundle/focused-chunks/chunk-55BIB6DV.js +2 -0
  34. package/dist/cli-bundle/focused-chunks/chunk-6JW6Z2P5.js +8 -0
  35. package/dist/cli-bundle/focused-chunks/{chunk-IW43E4XL.js → chunk-BKPIY34S.js} +2 -2
  36. package/dist/cli-bundle/focused-chunks/chunk-D4PIWE6D.js +2 -0
  37. package/dist/cli-bundle/focused-chunks/{chunk-KR5RVXLQ.js → chunk-DPO7TEFX.js} +29 -29
  38. package/dist/cli-bundle/focused-chunks/{chunk-JMVA4HKR.js → chunk-E3KCL7AY.js} +2 -2
  39. package/dist/cli-bundle/focused-chunks/chunk-ERAAFLPS.js +153 -0
  40. package/dist/cli-bundle/focused-chunks/{chunk-RIIN5V4N.js → chunk-F6E4JZKG.js} +2 -2
  41. package/dist/cli-bundle/focused-chunks/chunk-FPSYO5ZG.js +18 -0
  42. package/dist/cli-bundle/focused-chunks/{chunk-M6RPIXKC.js → chunk-J5EKAIVD.js} +2 -2
  43. package/dist/cli-bundle/focused-chunks/{chunk-2EXI2DKR.js → chunk-KDH5OX3D.js} +2 -2
  44. package/dist/cli-bundle/focused-chunks/chunk-OJ3LVVIS.js +2 -0
  45. package/dist/cli-bundle/focused-chunks/{chunk-DZGAHZZV.js → chunk-TL5M2PAY.js} +2 -2
  46. package/dist/cli-bundle/focused-chunks/{chunk-75774JWP.js → chunk-UDAZWT25.js} +2 -2
  47. package/dist/cli-bundle/focused-chunks/chunk-VABB4L5Y.js +17 -0
  48. package/dist/cli-bundle/main.js +13 -13
  49. package/dist/cli-bundle/sdk-authoring.js +1 -1
  50. package/dist/cli-bundle/sdk-contracts.js +1 -1
  51. package/dist/cli-bundle/sdk-core.js +41 -39
  52. package/dist/cli-bundle/sdk-governance.js +1 -1
  53. package/dist/cli-bundle/sdk-graph.js +1 -1
  54. package/dist/cli-bundle/sdk-merge.js +1 -1
  55. package/dist/cli-bundle/sdk-query.js +1 -1
  56. package/dist/cli-bundle/sdk-runtime.js +1 -1
  57. package/dist/cli-bundle/sdk-testing.js +1 -1
  58. package/dist/cli-bundle/sdk.js +2 -2
  59. package/dist/core/session/session-state.d.ts +47 -0
  60. package/dist/core/session/session-state.js +207 -6
  61. package/dist/core/shared/author.d.ts +7 -1
  62. package/dist/core/shared/author.js +66 -46
  63. package/dist/core/shared/errors.d.ts +8 -0
  64. package/dist/core/shared/errors.js +2 -2
  65. package/dist/sdk/agent/refusal-reachability.d.ts +40 -0
  66. package/dist/sdk/agent/refusal-reachability.js +72 -0
  67. package/dist/sdk/agent/subcommand-recovery.d.ts +40 -0
  68. package/dist/sdk/agent/subcommand-recovery.js +84 -0
  69. package/dist/sdk/cli-bootstrap.d.ts +8 -0
  70. package/dist/sdk/cli-bootstrap.js +7 -7
  71. package/dist/sdk/cli-contracts/completeness.js +13 -3
  72. package/dist/sdk/cli-contracts/enum-contracts.d.ts +1 -1
  73. package/dist/sdk/cli-contracts/enum-contracts.js +3 -2
  74. package/dist/sdk/cli-contracts/flag-contracts.d.ts +2 -0
  75. package/dist/sdk/cli-contracts/flag-contracts.js +17 -2
  76. package/dist/sdk/cli-contracts/runtime-contracts.js +4 -3
  77. package/dist/sdk/cli-contracts/schemas/assurance-definition.d.ts +513 -0
  78. package/dist/sdk/cli-contracts/schemas/assurance-definition.js +251 -0
  79. package/dist/sdk/cli-contracts/tool-parameter-tables.js +79 -2
  80. package/dist/sdk/cli-contracts/tool-schema.d.ts +2 -2
  81. package/dist/sdk/cli-contracts/tool-schema.js +34 -4
  82. package/dist/sdk/cli-contracts.d.ts +1 -1
  83. package/dist/sdk/cli-contracts.js +3 -3
  84. package/dist/sdk/completion.js +9 -3
  85. package/dist/sdk/config.js +9 -3
  86. package/dist/sdk/context/semantic-session-attribution.d.ts +32 -0
  87. package/dist/sdk/context/semantic-session-attribution.js +83 -0
  88. package/dist/sdk/core-governance.d.ts +3 -1
  89. package/dist/sdk/core-governance.js +5 -3
  90. package/dist/sdk/core.d.ts +1 -1
  91. package/dist/sdk/core.js +2 -2
  92. package/dist/sdk/error-code-catalog.d.ts +13 -0
  93. package/dist/sdk/error-code-catalog.js +35 -2
  94. package/dist/sdk/extension.js +18 -17
  95. package/dist/sdk/files.d.ts +11 -0
  96. package/dist/sdk/files.js +82 -24
  97. package/dist/sdk/generated-error-code-catalog.js +32 -13
  98. package/dist/sdk/governance/assurance-action-contracts.d.ts +7 -0
  99. package/dist/sdk/governance/assurance-action-contracts.js +5 -0
  100. package/dist/sdk/governance/assurance-action.d.ts +70 -0
  101. package/dist/sdk/governance/assurance-action.js +198 -0
  102. package/dist/sdk/governance/assurance-limits.d.ts +7 -0
  103. package/dist/sdk/governance/assurance-limits.js +11 -0
  104. package/dist/sdk/governance/assurance-runtime.d.ts +20 -0
  105. package/dist/sdk/governance/assurance-runtime.js +131 -0
  106. package/dist/sdk/governance/assurance.d.ts +432 -0
  107. package/dist/sdk/governance/assurance.js +689 -0
  108. package/dist/sdk/graph/run.js +8 -3
  109. package/dist/sdk/index.d.ts +6 -1
  110. package/dist/sdk/index.js +8 -3
  111. package/dist/sdk/lifecycle/claim.js +18 -3
  112. package/dist/sdk/lifecycle/focus.js +13 -3
  113. package/dist/sdk/lifecycle/plan.js +8 -3
  114. package/dist/sdk/provenance.d.ts +38 -0
  115. package/dist/sdk/provenance.js +64 -2
  116. package/dist/sdk/query/context.js +19 -8
  117. package/dist/sdk/runtime-extended-actions.js +22 -5
  118. package/dist/sdk/runtime-primitives.d.ts +2 -0
  119. package/dist/sdk/runtime-primitives.js +4 -2
  120. package/dist/sdk/runtime.d.ts +4 -0
  121. package/dist/sdk/runtime.js +31 -27
  122. package/dist/sdk/telemetry.js +7 -4
  123. package/dist/sdk/traceability/runtime-files-lookup.d.ts +8 -0
  124. package/dist/sdk/traceability/runtime-files-lookup.js +33 -0
  125. package/dist/sdk/traceability/source-traceability.d.ts +102 -0
  126. package/dist/sdk/traceability/source-traceability.js +293 -0
  127. package/dist/types.d.ts +8 -2
  128. package/dist/types.js +2 -2
  129. package/docs/ASSURANCE.md +132 -0
  130. package/docs/README.md +1 -0
  131. package/docs/RELEASING.md +9 -5
  132. package/docs/SDK.md +12 -1
  133. package/docs/SDK_AGENT_SESSION_CONTEXT.md +40 -4
  134. package/docs/SDK_EVIDENCE_TRACEABILITY.md +39 -1
  135. package/docs/SDK_RUNTIME_BOUNDARIES.md +36 -1
  136. package/docs/TESTING.md +12 -9
  137. package/docs/generated/AGENT_COMMAND_SURFACE.md +1 -0
  138. package/marketplace.json +2 -2
  139. package/package.json +3 -3
  140. package/packages/pm-beads/package.json +1 -1
  141. package/packages/pm-calendar/package.json +1 -1
  142. package/packages/pm-command-kit/package.json +1 -1
  143. package/packages/pm-digital-twin/package.json +1 -1
  144. package/packages/pm-governance-audit/package.json +1 -1
  145. package/packages/pm-guide-shell/package.json +1 -1
  146. package/packages/pm-kanban/package.json +1 -1
  147. package/packages/pm-lifecycle-hooks/package.json +1 -1
  148. package/packages/pm-linked-test-adapters/package.json +1 -1
  149. package/packages/pm-search-advanced/package.json +1 -1
  150. package/packages/pm-templates/extensions/templates/index.ts +9 -3
  151. package/packages/pm-templates/package.json +1 -1
  152. package/packages/pm-todos/package.json +1 -1
  153. package/packages/pm-vcs/package.json +1 -1
  154. package/plugins/pm-claude/.claude-plugin/plugin.json +1 -1
  155. package/plugins/pm-codex/.codex-plugin/plugin.json +1 -1
  156. package/sdk/public-surface.json +840 -28
  157. package/dist/cli-bundle/chunks/chunk-2QYH4QMI.js +0 -30
  158. package/dist/cli-bundle/chunks/chunk-JUDU4RO4.js +0 -194
  159. package/dist/cli-bundle/chunks/chunk-JZSNADRR.js +0 -5
  160. package/dist/cli-bundle/chunks/chunk-MENWVGJW.js +0 -2
  161. package/dist/cli-bundle/chunks/chunk-S4EITGLA.js +0 -3
  162. package/dist/cli-bundle/chunks/chunk-TIGKWVLA.js +0 -13
  163. package/dist/cli-bundle/chunks/chunk-TSLDTJLQ.js +0 -2
  164. package/dist/cli-bundle/chunks/register-mutation-DKI7QC7O.js +0 -20
  165. package/dist/cli-bundle/chunks/register-operations-P5OGMT6I.js +0 -2
  166. package/dist/cli-bundle/focused-chunks/chunk-36FTZ2NT.js +0 -2
  167. package/dist/cli-bundle/focused-chunks/chunk-3CQECMKR.js +0 -16
  168. package/dist/cli-bundle/focused-chunks/chunk-CHIBMEZR.js +0 -8
  169. package/dist/cli-bundle/focused-chunks/chunk-FF4MNAYB.js +0 -153
  170. package/dist/cli-bundle/focused-chunks/chunk-GHTN2ILR.js +0 -2
  171. package/dist/cli-bundle/focused-chunks/chunk-I4YM2I7S.js +0 -2
  172. package/dist/cli-bundle/focused-chunks/chunk-IMDTEN7K.js +0 -2
  173. package/dist/cli-bundle/focused-chunks/chunk-KSNJG4KI.js +0 -16
  174. package/dist/cli-bundle/focused-chunks/chunk-MXYSIQ56.js +0 -18
  175. package/dist/cli-bundle/focused-chunks/chunk-RKWSCYYN.js +0 -2
@@ -0,0 +1,32 @@
1
+ import { type AgentSemanticAttribution } from "../../core/session/session-state.js";
2
+ import { readSettings } from "../../core/store/settings.js";
3
+ /** Resolve an item's canonical parent lineage under a strict depth bound. */
4
+ export declare function resolveSemanticLineageIds(pmRoot: string, settings: Awaited<ReturnType<typeof readSettings>>, itemId: string): Promise<string[]>;
5
+ /** Record one successful claim and its bounded canonical lineage. */
6
+ export declare function recordClaimSemanticAttribution(params: {
7
+ pmRoot: string;
8
+ settings: Awaited<ReturnType<typeof readSettings>>;
9
+ principal: string;
10
+ itemId: string;
11
+ }): Promise<void>;
12
+ /** Remove one released claim from the active semantic workset. */
13
+ export declare function recordReleaseSemanticAttribution(params: {
14
+ pmRoot: string;
15
+ principal: string;
16
+ itemId: string;
17
+ }): Promise<void>;
18
+ /** Set or clear focused semantic work with canonical lineage evidence. */
19
+ export declare function recordFocusSemanticAttribution(params: {
20
+ pmRoot: string;
21
+ settings: Awaited<ReturnType<typeof readSettings>>;
22
+ principal: string;
23
+ itemId?: string;
24
+ }): Promise<void>;
25
+ /** Public constants used by scale and negative-control tests. */
26
+ export declare const SEMANTIC_ATTRIBUTION_LIMITS: {
27
+ readonly lineage_depth: 16;
28
+ readonly active_items: 64;
29
+ readonly evidence_rows: 32;
30
+ };
31
+ /** Convert bounded claim/focus evidence into normalized context affinity. */
32
+ export declare function semanticAttributionAffinity(attribution: AgentSemanticAttribution | undefined): Readonly<Record<string, number>> | undefined;
@@ -0,0 +1,83 @@
1
+ /**
2
+ * @module sdk/semantic-session-attribution
3
+ *
4
+ * Maintains bounded claimed/focused lineage evidence used by automatic
5
+ * mutation provenance without scanning history or retaining prompt content.
6
+ */
7
+
8
+ !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]="97c1e310-3cd9-5846-a54c-d019b0351541")}catch(e){}}();
9
+ import { getActiveExtensionRegistrations } from "../../core/extensions/index.js";
10
+ import { resolveItemTypeRegistry } from "../../core/item/type-registry.js";
11
+ import { recordClaimedWorkAttribution, recordFocusedWorkAttribution, releaseClaimedWorkAttribution, } from "../../core/session/session-state.js";
12
+ import { locateItem, readLocatedItem } from "../../core/store/item-store.js";
13
+ const MAX_SEMANTIC_LINEAGE_DEPTH = 16;
14
+ /** Resolve an item's canonical parent lineage under a strict depth bound. */
15
+ export async function resolveSemanticLineageIds(pmRoot, settings, itemId) {
16
+ const typeToFolder = resolveItemTypeRegistry(settings, getActiveExtensionRegistrations()).type_to_folder;
17
+ const lineage = [];
18
+ const seen = new Set();
19
+ let cursor = itemId;
20
+ while (cursor && lineage.length < MAX_SEMANTIC_LINEAGE_DEPTH) {
21
+ const normalized = cursor.trim().toLowerCase();
22
+ if (!normalized || seen.has(normalized))
23
+ break;
24
+ seen.add(normalized);
25
+ const located = await locateItem(pmRoot, cursor, settings.id_prefix, settings.item_format, typeToFolder);
26
+ if (!located)
27
+ break;
28
+ const loaded = await readLocatedItem(located, { schema: settings.schema });
29
+ lineage.push(loaded.document.metadata.id);
30
+ cursor = loaded.document.metadata.parent;
31
+ }
32
+ return lineage;
33
+ }
34
+ /** Record one successful claim and its bounded canonical lineage. */
35
+ export async function recordClaimSemanticAttribution(params) {
36
+ await recordClaimedWorkAttribution({
37
+ pmRoot: params.pmRoot,
38
+ principal: params.principal,
39
+ itemId: params.itemId,
40
+ lineageIds: await resolveSemanticLineageIds(params.pmRoot, params.settings, params.itemId),
41
+ });
42
+ }
43
+ /** Remove one released claim from the active semantic workset. */
44
+ export async function recordReleaseSemanticAttribution(params) {
45
+ await releaseClaimedWorkAttribution(params);
46
+ }
47
+ /** Set or clear focused semantic work with canonical lineage evidence. */
48
+ export async function recordFocusSemanticAttribution(params) {
49
+ await recordFocusedWorkAttribution({
50
+ pmRoot: params.pmRoot,
51
+ principal: params.principal,
52
+ ...(params.itemId
53
+ ? {
54
+ itemId: params.itemId,
55
+ lineageIds: await resolveSemanticLineageIds(params.pmRoot, params.settings, params.itemId),
56
+ }
57
+ : {}),
58
+ });
59
+ }
60
+ /** Public constants used by scale and negative-control tests. */
61
+ export const SEMANTIC_ATTRIBUTION_LIMITS = {
62
+ lineage_depth: MAX_SEMANTIC_LINEAGE_DEPTH,
63
+ active_items: 64,
64
+ evidence_rows: 32,
65
+ };
66
+ /** Convert bounded claim/focus evidence into normalized context affinity. */
67
+ export function semanticAttributionAffinity(attribution) {
68
+ if (!attribution)
69
+ return undefined;
70
+ const affinity = {};
71
+ for (const itemId of attribution.active_item_ids)
72
+ affinity[itemId] = 1;
73
+ if (attribution.focused_item_id)
74
+ affinity[attribution.focused_item_id] = 1;
75
+ for (const evidence of attribution.evidence) {
76
+ const lineage = /^lineage:(.+)$/u.exec(evidence)?.[1];
77
+ if (lineage && affinity[lineage] === undefined)
78
+ affinity[lineage] = 0.75;
79
+ }
80
+ return Object.keys(affinity).length > 0 ? affinity : undefined;
81
+ }
82
+ //# sourceMappingURL=semantic-session-attribution.js.map
83
+ //# debugId=97c1e310-3cd9-5846-a54c-d019b0351541
@@ -5,5 +5,7 @@
5
5
  * exposed by both the focused core entrypoint and the complete SDK barrel.
6
6
  */
7
7
  export { AGENT_PROVENANCE_DIMENSIONS, BUILTIN_HARNESS_SIGNAL_DESCRIPTORS, diagnoseAgentIdentity, detectAgentIdentity, detectHarnessIdentity, readAuthorEnvironment, registerHarnessSignalDescriptors, resolveAuthorIdentity, runWithHarnessDetectionSignals, runWithWorkspaceHarnessSignalDescriptors, writeAuthorEnvironment, type AgentClientInfo, type AgentModelSource, type AgentProvenance, type AgentProvenanceAbsenceReason, type AgentProvenanceObservation, type AgentProvenanceOutcome, type AuthorSource, type DetectedAgentIdentity, type DiagnosedAgentIdentity, type HarnessDetectionSignals, type HarnessSignalDescriptor, type ResolvedAuthorIdentity, } from "../core/shared/author.js";
8
- export { analyzeAgentProvenanceDescriptorCoverage, groupHistoryByEpisode, resolveHistoryEpisodeGroupIdentity, summarizeAgentProvenance, summarizeAgentModelProvenance, type AgentEpisodeGroup, type AgentModelProvenanceCoverage, type AgentProvenanceDimensionCoverage, type AgentProvenanceDescriptorCoverage, } from "./provenance.js";
8
+ export { SEMANTIC_ATTRIBUTION_LIMITS, recordClaimSemanticAttribution, recordFocusSemanticAttribution, recordReleaseSemanticAttribution, resolveSemanticLineageIds, semanticAttributionAffinity, } from "./context/semantic-session-attribution.js";
9
+ export { explainSourceTraceability, parseSourceLineRange, type SourceDecisionPath, type SourceLineRange, type SourceTraceabilityEvidence, type SourceTraceabilityExplanation, type SourceTraceabilityRationale, type SourceTraceabilityReceipt, } from "./traceability/source-traceability.js";
10
+ export { analyzeAgentProvenanceDescriptorCoverage, evaluateSemanticAttributionCoverage, groupHistoryByEpisode, resolveHistoryEpisodeGroupIdentity, summarizeAgentProvenance, summarizeAgentModelProvenance, type AgentEpisodeGroup, type AgentModelProvenanceCoverage, type AgentProvenanceDimensionCoverage, type AgentProvenanceDescriptorCoverage, type AgentSemanticAttributionCoverage, type AgentSemanticAttributionCoverageGate, } from "./provenance.js";
9
11
  export { analyzeSdkCliParameterCompleteness, type SdkCliActionParameterCoverage, type SdkCliCompletenessContractSource, type SdkCliParameterCoverageEntry, type SdkCliParameterDisposition, } from "./cli-contracts.js";
@@ -5,9 +5,11 @@
5
5
  * exposed by both the focused core entrypoint and the complete SDK barrel.
6
6
  */
7
7
 
8
- !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]="7442357d-52b9-5461-9ac4-3acd898334da")}catch(e){}}();
8
+ !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]="d19cfa31-a02f-53a7-8685-5d169d6e051d")}catch(e){}}();
9
9
  export { AGENT_PROVENANCE_DIMENSIONS, BUILTIN_HARNESS_SIGNAL_DESCRIPTORS, diagnoseAgentIdentity, detectAgentIdentity, detectHarnessIdentity, readAuthorEnvironment, registerHarnessSignalDescriptors, resolveAuthorIdentity, runWithHarnessDetectionSignals, runWithWorkspaceHarnessSignalDescriptors, writeAuthorEnvironment, } from "../core/shared/author.js";
10
- export { analyzeAgentProvenanceDescriptorCoverage, groupHistoryByEpisode, resolveHistoryEpisodeGroupIdentity, summarizeAgentProvenance, summarizeAgentModelProvenance, } from "./provenance.js";
10
+ export { SEMANTIC_ATTRIBUTION_LIMITS, recordClaimSemanticAttribution, recordFocusSemanticAttribution, recordReleaseSemanticAttribution, resolveSemanticLineageIds, semanticAttributionAffinity, } from "./context/semantic-session-attribution.js";
11
+ export { explainSourceTraceability, parseSourceLineRange, } from "./traceability/source-traceability.js";
12
+ export { analyzeAgentProvenanceDescriptorCoverage, evaluateSemanticAttributionCoverage, groupHistoryByEpisode, resolveHistoryEpisodeGroupIdentity, summarizeAgentProvenance, summarizeAgentModelProvenance, } from "./provenance.js";
11
13
  export { analyzeSdkCliParameterCompleteness, } from "./cli-contracts.js";
12
14
  //# sourceMappingURL=core-governance.js.map
13
- //# debugId=7442357d-52b9-5461-9ac4-3acd898334da
15
+ //# debugId=d19cfa31-a02f-53a7-8685-5d169d6e051d
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * Provides the stable item lifecycle client and universal project data types.
5
5
  */
6
- export { BASELINE_ITEM_FORMAT_VERSION, BUILTIN_ITEM_TYPE_VALUES, CONFIDENCE_TEXT_VALUES, CURRENT_ITEM_FORMAT_VERSION, DEPENDENCY_KIND_VALUES, EXIT_CODE, ISSUE_SEVERITY_VALUES, ITEM_TYPE_VALUES, PM_CLI_EXPECTED_ERROR_NAME, PmCliError, PmClient, RISK_VALUES, STATUS_VALUES, canonicalDocument, classifyItemFormatVersion, createPmCliExpectedError, effectiveItemFormatVersion, emptyImportedDocument, isPmCliExpectedError, normalizeItemFormatVersion, normalizeItemId, normalizeStatusInput, nowIso, runAction, serializeItemDocument, aggregate, append, claim, claimNext, close, comments, context, copy, create, deleteItem, deps, docs, files, filesDiscover, focus, get, graph, learnings, list, next, notes, release, restore, search, update, type AggregateOptions, type AggregateResult, type AggregateRow, type AppendCommandOptions, type AppendResult, type ClaimNextOptions, type ClaimResult, type CloseResult, type CommentsCommandOptions, type CommentsResult, type ContextOptions, type ContextResult, type CopyResult, type CreateResult, type Dependency, type DeleteResult, type DepsCommandOptions, type DepsResult, type DocsCommandOptions, type DocsResult, type FilesCommandOptions, type FilesDiscoverOptions, type FilesDiscoverResult, type FilesResult, type FocusResult, type GetOptions, type GetResult, type ItemFormatVersionScanEntry, type ItemFormatVersionScanResult, type ItemFormatVersionStatus, type LearningsCommandOptions, type LearningsResult, type ListOptions, type ListResult, type NextOptions, type NextResult, type NotesCommandOptions, type NotesResult, type PmActionInput, type PmActionName, type PmActionOptions, type PmClientOptions, type ReleaseResult, type RestoreResult, type SearchOptions, type SearchResult, type UpdateResult, } from "./runtime.js";
6
+ export { BASELINE_ITEM_FORMAT_VERSION, BUILTIN_ITEM_TYPE_VALUES, CONFIDENCE_TEXT_VALUES, CURRENT_ITEM_FORMAT_VERSION, DEPENDENCY_KIND_VALUES, EXIT_CODE, ISSUE_SEVERITY_VALUES, ITEM_TYPE_VALUES, PM_CLI_EXPECTED_ERROR_NAME, PmCliError, PmClient, RISK_VALUES, STATUS_VALUES, canonicalDocument, classifyItemFormatVersion, createPmCliExpectedError, effectiveItemFormatVersion, emptyImportedDocument, isPmCliExpectedError, normalizeItemFormatVersion, normalizeItemId, normalizeStatusInput, nowIso, runAction, serializeItemDocument, aggregate, append, claim, claimNext, close, comments, context, copy, create, deleteItem, deps, docs, files, filesDiscover, focus, get, graph, learnings, list, next, notes, release, restore, search, update, type AggregateOptions, type AggregateResult, type AggregateRow, type AssuranceActionInput, type AssuranceActionResult, type AppendCommandOptions, type AppendResult, type ClaimNextOptions, type ClaimResult, type CloseResult, type CommentsCommandOptions, type CommentsResult, type ContextOptions, type ContextResult, type CopyResult, type CreateResult, type Dependency, type DeleteResult, type DepsCommandOptions, type DepsResult, type DocsCommandOptions, type DocsResult, type FilesCommandOptions, type FilesDiscoverOptions, type FilesDiscoverResult, type FilesResult, type FocusResult, type GetOptions, type GetResult, type ItemFormatVersionScanEntry, type ItemFormatVersionScanResult, type ItemFormatVersionStatus, type LearningsCommandOptions, type LearningsResult, type ListOptions, type ListResult, type NextOptions, type NextResult, type NotesCommandOptions, type NotesResult, type PmActionInput, type PmActionName, type PmActionOptions, type PmClientOptions, type ReleaseResult, type RestoreResult, type SearchOptions, type SearchResult, type UpdateResult, } from "./runtime.js";
7
7
  export * from "./core-governance.js";
8
8
  export * from "./agent-session-context.js";
9
9
  export { PM_READ_OUTPUT_DIMENSIONS, PM_READ_OUTPUT_OPTION_FLAGS, PM_READ_OUTPUT_COMPOSITION_OPTION_FLAGS, PM_READ_OUTPUT_SURFACE_CONTRACTS, applyReadOutputDimensions, isReadOutputBudgetExceeded, resolveReadOutputDimensions, resolveReadOutputEncoding, resolveReadOutputSurface, validateReadOutputOptions, } from "./read-output-contracts.js";
package/dist/sdk/core.js CHANGED
@@ -4,11 +4,11 @@
4
4
  * Provides the stable item lifecycle client and universal project data types.
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]="54d31df7-e708-585d-9fb2-3c5ddfcc6138")}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]="c2f56389-6238-5b5c-add8-00296fe401b6")}catch(e){}}();
8
8
  export { BASELINE_ITEM_FORMAT_VERSION, BUILTIN_ITEM_TYPE_VALUES, CONFIDENCE_TEXT_VALUES, CURRENT_ITEM_FORMAT_VERSION, DEPENDENCY_KIND_VALUES, EXIT_CODE, ISSUE_SEVERITY_VALUES, ITEM_TYPE_VALUES, PM_CLI_EXPECTED_ERROR_NAME, PmCliError, PmClient, RISK_VALUES, STATUS_VALUES, canonicalDocument, classifyItemFormatVersion, createPmCliExpectedError, effectiveItemFormatVersion, emptyImportedDocument, isPmCliExpectedError, normalizeItemFormatVersion, normalizeItemId, normalizeStatusInput, nowIso, runAction, serializeItemDocument, aggregate, append, claim, claimNext, close, comments, context, copy, create, deleteItem, deps, docs, files, filesDiscover, focus, get, graph, learnings, list, next, notes, release, restore, search, update, } from "./runtime.js";
9
9
  export * from "./core-governance.js";
10
10
  export * from "./agent-session-context.js";
11
11
  export { PM_READ_OUTPUT_DIMENSIONS, PM_READ_OUTPUT_OPTION_FLAGS, PM_READ_OUTPUT_COMPOSITION_OPTION_FLAGS, PM_READ_OUTPUT_SURFACE_CONTRACTS, applyReadOutputDimensions, isReadOutputBudgetExceeded, resolveReadOutputDimensions, resolveReadOutputEncoding, resolveReadOutputSurface, validateReadOutputOptions, } from "./read-output-contracts.js";
12
12
  export { applyReadOutputSessionReferences, attachReadOutputSessionReceipt, parseReadOutputSession, readOutputSessionRemainingTokens, } from "./read-output-session.js";
13
13
  //# sourceMappingURL=core.js.map
14
- //# debugId=54d31df7-e708-585d-9fb2-3c5ddfcc6138
14
+ //# debugId=c2f56389-6238-5b5c-add8-00296fe401b6
@@ -8,6 +8,17 @@
8
8
  export type PmErrorCodeStability = "provisional" | "stable";
9
9
  /** Semantic process-exit class shared by shell and SDK consumers. */
10
10
  export type PmErrorCodeClass = "generic_failure" | "usage" | "not_found" | "conflict" | "dependency_failed";
11
+ /** One externally observable refusal state and its executable entrypoint probe. */
12
+ export interface PmRefusalStateContract {
13
+ /** Stable semantic state owned by the error code. */
14
+ state: string;
15
+ /** Stable probe identifier implemented by the entrypoint conformance suite. */
16
+ probe_id: string;
17
+ /** Public command roots through which the state must remain reachable. */
18
+ entrypoints: string[];
19
+ /** Exit class expected when the probe reaches the state. */
20
+ expected_exit_class: PmErrorCodeClass;
21
+ }
11
22
  /** Stable shell exit-code taxonomy shared by every structured error. */
12
23
  export declare const PM_ERROR_CODE_EXIT_CLASS_CONTRACTS: readonly [{
13
24
  readonly exit_code: 1;
@@ -47,6 +58,8 @@ export interface PmErrorCodeContract {
47
58
  canonical_code?: string;
48
59
  /** Stable compatibility spellings that resolve to this canonical code. */
49
60
  aliases?: string[];
61
+ /** Observable states this code claims, each backed by a real-entrypoint probe. */
62
+ owned_states?: PmRefusalStateContract[];
50
63
  }
51
64
  /** Validate, normalize, sort, and freeze an error-code catalog. */
52
65
  export declare function definePmErrorCodeCatalog(declarations: readonly PmErrorCodeContract[]): readonly PmErrorCodeContract[];
@@ -6,7 +6,7 @@
6
6
  */
7
7
  /** Stable shell exit-code taxonomy shared by every structured error. */
8
8
 
9
- !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]="393243a5-dd90-52c1-a9c1-588fd33f8b6a")}catch(e){}}();
9
+ !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]="c76fa303-6672-5c1e-9cf5-3a08bd3a7814")}catch(e){}}();
10
10
  export const PM_ERROR_CODE_EXIT_CLASS_CONTRACTS = [
11
11
  { exit_code: 1, class: "generic_failure" },
12
12
  { exit_code: 2, class: "usage" },
@@ -21,6 +21,34 @@ function normalizeContractList(values) {
21
21
  ...new Set(values.map((value) => value.trim()).filter(Boolean)),
22
22
  ].sort();
23
23
  }
24
+ function normalizeOwnedStates(states) {
25
+ if (!states)
26
+ return [];
27
+ const seenStates = new Set();
28
+ const seenProbes = new Set();
29
+ return states
30
+ .map((state) => {
31
+ const normalizedState = state.state.trim();
32
+ const probeId = state.probe_id.trim();
33
+ const entrypoints = normalizeContractList(state.entrypoints);
34
+ if (!/^[a-z][a-z0-9_]*$/.test(normalizedState) ||
35
+ !/^[a-z][a-z0-9-]*$/.test(probeId) ||
36
+ entrypoints.length === 0 ||
37
+ seenStates.has(normalizedState) ||
38
+ seenProbes.has(probeId)) {
39
+ throw new TypeError("Invalid pm refusal state contract");
40
+ }
41
+ seenStates.add(normalizedState);
42
+ seenProbes.add(probeId);
43
+ return {
44
+ state: normalizedState,
45
+ probe_id: probeId,
46
+ entrypoints,
47
+ expected_exit_class: state.expected_exit_class,
48
+ };
49
+ })
50
+ .sort((left, right) => left.state.localeCompare(right.state));
51
+ }
24
52
  function isValidNormalizedErrorCodeContract(declaration, sources, emittingCommands, canonicalCode, aliases) {
25
53
  return ![
26
54
  [1, 2, 3, 4, 5].includes(declaration.exit_code),
@@ -86,9 +114,13 @@ export function definePmErrorCodeCatalog(declarations) {
86
114
  const emittingCommands = normalizeContractList(declaration.emitting_commands);
87
115
  const canonicalCode = (declaration.canonical_code ?? code).trim();
88
116
  const aliases = normalizeContractList(declaration.aliases ?? []);
117
+ const ownedStates = normalizeOwnedStates(declaration.owned_states);
89
118
  if (!isValidNormalizedErrorCodeContract(declaration, sources, emittingCommands, canonicalCode, aliases)) {
90
119
  throw new TypeError(`Invalid pm error code contract: ${code}`);
91
120
  }
121
+ if (ownedStates.some((state) => state.expected_exit_class !== declaration.class)) {
122
+ throw new TypeError(`Invalid pm refusal state exit class: ${code}`);
123
+ }
92
124
  return Object.freeze({
93
125
  ...declaration,
94
126
  code,
@@ -98,6 +130,7 @@ export function definePmErrorCodeCatalog(declarations) {
98
130
  emitting_commands: emittingCommands,
99
131
  canonical_code: canonicalCode,
100
132
  aliases,
133
+ owned_states: ownedStates,
101
134
  });
102
135
  });
103
136
  validateErrorCodeAliases(normalized);
@@ -118,4 +151,4 @@ export function resolvePmErrorCodeContract(code, catalog) {
118
151
  return contract;
119
152
  }
120
153
  //# sourceMappingURL=error-code-catalog.js.map
121
- //# debugId=393243a5-dd90-52c1-a9c1-588fd33f8b6a
154
+ //# debugId=c76fa303-6672-5c1e-9cf5-3a08bd3a7814
@@ -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,7 +4,7 @@
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]="94952ea0-bfe7-5d64-9ac4-101c483b4c55")}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([
@@ -116,6 +116,18 @@ export const PM_ERROR_CODE_CATALOG = definePmErrorCodeCatalog([
116
116
  canonical_code: "append_empty_body",
117
117
  aliases: [],
118
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
+ },
119
131
  {
120
132
  code: "body_file_conflicts_with_body",
121
133
  meaning: "Body file conflicts with body condition.",
@@ -2246,13 +2258,16 @@ export const PM_ERROR_CODE_CATALOG = definePmErrorCodeCatalog([
2246
2258
  code: "tracker_not_initialized",
2247
2259
  meaning: "Tracker not initialized condition.",
2248
2260
  stability: "stable",
2249
- exit_code: 1,
2250
- class: "generic_failure",
2261
+ exit_code: 3,
2262
+ class: "not_found",
2251
2263
  recovery: "Inspect the structured error guidance and retry the suggested command.",
2252
2264
  sources: ["cli/error-guidance.ts", "core/telemetry/observability.ts"],
2253
2265
  emitting_commands: ["*"],
2254
2266
  canonical_code: "tracker_not_initialized",
2255
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
+ ],
2256
2271
  },
2257
2272
  {
2258
2273
  code: "tracker_root_missing",
@@ -2385,9 +2400,9 @@ export const PM_ERROR_CODE_CATALOG = definePmErrorCodeCatalog([
2385
2400
  exit_code: 2,
2386
2401
  class: "usage",
2387
2402
  recovery: "Inspect the structured error guidance and retry the suggested command.",
2388
- sources: ["sdk/extension.ts"],
2403
+ sources: ["sdk/agent/subcommand-recovery.ts"],
2389
2404
  emitting_commands: ["*"],
2390
- canonical_code: "unknown_lifecycle_action",
2405
+ canonical_code: "unknown_subcommand",
2391
2406
  aliases: [],
2392
2407
  },
2393
2408
  {
@@ -2401,6 +2416,9 @@ export const PM_ERROR_CODE_CATALOG = definePmErrorCodeCatalog([
2401
2416
  emitting_commands: ["*"],
2402
2417
  canonical_code: "unknown_option",
2403
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
+ ],
2404
2422
  },
2405
2423
  {
2406
2424
  code: "unknown_plan_template",
@@ -2445,15 +2463,16 @@ export const PM_ERROR_CODE_CATALOG = definePmErrorCodeCatalog([
2445
2463
  exit_code: 2,
2446
2464
  class: "usage",
2447
2465
  recovery: "Inspect the structured error guidance and retry the suggested command.",
2448
- sources: [
2449
- "cli/register-mutation.ts",
2450
- "cli/register-operations.ts",
2451
- "sdk/runtime-extended-actions.ts",
2452
- "sdk/telemetry.ts",
2453
- ],
2466
+ sources: ["cli/error-guidance.ts", "sdk/agent/subcommand-recovery.ts"],
2454
2467
  emitting_commands: ["*"],
2455
2468
  canonical_code: "unknown_subcommand",
2456
- 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
+ ],
2457
2476
  },
2458
2477
  {
2459
2478
  code: "unsupported_update_option",
@@ -3129,4 +3148,4 @@ export const PM_ERROR_CODE_CATALOG = definePmErrorCodeCatalog([
3129
3148
  },
3130
3149
  ]);
3131
3150
  //# sourceMappingURL=generated-error-code-catalog.js.map
3132
- //# debugId=94952ea0-bfe7-5d64-9ac4-101c483b4c55
3151
+ //# debugId=07d93565-d5ef-5c3d-ae8a-214973e6ec20