@pie-players/pie-assessment-toolkit 0.3.44 → 0.3.45

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 (191) hide show
  1. package/README.md +54 -69
  2. package/dist/components/ItemToolBar.custom-element.js +479 -324
  3. package/dist/components/PieAssessmentToolkit.custom-element.js +19498 -3590
  4. package/dist/components/SectionToolBar.custom-element.js +761 -507
  5. package/dist/index.d.ts +3 -6
  6. package/dist/index.js +1 -3
  7. package/dist/index.js.map +1 -1
  8. package/dist/policy/core/ToolPolicyEngine.d.ts +1 -2
  9. package/dist/policy/core/ToolPolicyEngine.js +1 -2
  10. package/dist/policy/core/ToolPolicyEngine.js.map +1 -1
  11. package/dist/policy/core/pnp-policy-inputs.d.ts +2 -3
  12. package/dist/policy/core/pnp-policy-inputs.js +2 -3
  13. package/dist/policy/core/pnp-policy-inputs.js.map +1 -1
  14. package/dist/policy/core/provenance.d.ts +7 -34
  15. package/dist/policy/core/provenance.js +4 -21
  16. package/dist/policy/core/provenance.js.map +1 -1
  17. package/dist/policy/sources/PnpPolicySource.d.ts +6 -19
  18. package/dist/policy/sources/PnpPolicySource.js +6 -19
  19. package/dist/policy/sources/PnpPolicySource.js.map +1 -1
  20. package/dist/runtime/SectionRuntimeEngine.d.ts +13 -28
  21. package/dist/runtime/SectionRuntimeEngine.js +13 -27
  22. package/dist/runtime/SectionRuntimeEngine.js.map +1 -1
  23. package/dist/runtime/adapter/SectionEngineAdapter.d.ts +2 -2
  24. package/dist/runtime/adapter/SectionEngineAdapter.js +2 -2
  25. package/dist/runtime/adapter/SectionEngineAdapter.js.map +1 -1
  26. package/dist/runtime/adapter/coordinator-bridge.d.ts +1 -1
  27. package/dist/runtime/adapter/coordinator-bridge.js +1 -1
  28. package/dist/runtime/adapter/coordinator-bridge.js.map +1 -1
  29. package/dist/runtime/adapter/dom-event-bridge.d.ts +1 -1
  30. package/dist/runtime/adapter/dom-event-bridge.js +1 -1
  31. package/dist/runtime/adapter/dom-event-bridge.js.map +1 -1
  32. package/dist/runtime/catalog-registration.d.ts +12 -0
  33. package/dist/runtime/catalog-registration.js +54 -0
  34. package/dist/runtime/catalog-registration.js.map +1 -0
  35. package/dist/runtime/core/engine-output.d.ts +2 -2
  36. package/dist/runtime/core/engine-output.js +2 -2
  37. package/dist/runtime/core/engine-output.js.map +1 -1
  38. package/dist/runtime/core/engine-readiness.d.ts +2 -2
  39. package/dist/runtime/core/engine-readiness.js.map +1 -1
  40. package/dist/runtime/core/engine-resolver.d.ts +13 -41
  41. package/dist/runtime/core/engine-resolver.js +19 -76
  42. package/dist/runtime/core/engine-resolver.js.map +1 -1
  43. package/dist/runtime/core/engine-transition.d.ts +1 -1
  44. package/dist/runtime/core/engine-transition.js +1 -1
  45. package/dist/runtime/core/engine-transition.js.map +1 -1
  46. package/dist/runtime/engine.d.ts +1 -1
  47. package/dist/runtime/engine.js.map +1 -1
  48. package/dist/runtime/section-runtime-engine-host-context.d.ts +22 -15
  49. package/dist/runtime/section-runtime-engine-host-context.js +10 -10
  50. package/dist/runtime/section-runtime-engine-host-context.js.map +1 -1
  51. package/dist/runtime/stage-emit-gate.d.ts +4 -4
  52. package/dist/runtime/stage-emit-gate.js +3 -3
  53. package/dist/runtime/stage-emit-gate.js.map +1 -1
  54. package/dist/services/AccessibilityCatalogResolver.d.ts +23 -0
  55. package/dist/services/AccessibilityCatalogResolver.js +200 -28
  56. package/dist/services/AccessibilityCatalogResolver.js.map +1 -1
  57. package/dist/services/HighlightCoordinator.d.ts +25 -0
  58. package/dist/services/HighlightCoordinator.js +125 -0
  59. package/dist/services/HighlightCoordinator.js.map +1 -1
  60. package/dist/services/SSMLExtractor.d.ts +16 -1
  61. package/dist/services/SSMLExtractor.js +86 -7
  62. package/dist/services/SSMLExtractor.js.map +1 -1
  63. package/dist/services/TTSService.d.ts +30 -4
  64. package/dist/services/TTSService.js +652 -159
  65. package/dist/services/TTSService.js.map +1 -1
  66. package/dist/services/ToolRegistry.d.ts +2 -2
  67. package/dist/services/ToolRegistry.js +1 -1
  68. package/dist/services/ToolRegistry.js.map +1 -1
  69. package/dist/services/ToolkitCoordinator.d.ts +16 -73
  70. package/dist/services/ToolkitCoordinator.js +34 -113
  71. package/dist/services/ToolkitCoordinator.js.map +1 -1
  72. package/dist/services/interfaces.d.ts +20 -2
  73. package/dist/services/interfaces.js.map +1 -1
  74. package/dist/services/tool-config-validation.d.ts +1 -1
  75. package/dist/services/tool-config-validation.js +7 -7
  76. package/dist/services/tool-config-validation.js.map +1 -1
  77. package/dist/services/tool-instance-id.js +1 -1
  78. package/dist/services/tool-instance-id.js.map +1 -1
  79. package/dist/services/tool-providers/TTSToolProvider.js +3 -3
  80. package/dist/services/tool-providers/TTSToolProvider.js.map +1 -1
  81. package/dist/services/tools-config-normalizer.d.ts +13 -2
  82. package/dist/services/tools-config-normalizer.js +3 -8
  83. package/dist/services/tools-config-normalizer.js.map +1 -1
  84. package/dist/services/tts/browser-provider.js +2 -0
  85. package/dist/services/tts/browser-provider.js.map +1 -1
  86. package/dist/services/tts/catalog-span-alignment.d.ts +39 -0
  87. package/dist/services/tts/catalog-span-alignment.js +300 -0
  88. package/dist/services/tts/catalog-span-alignment.js.map +1 -0
  89. package/dist/services/tts/generated-speech/assemble-plan.d.ts +33 -0
  90. package/dist/services/tts/generated-speech/assemble-plan.js +111 -0
  91. package/dist/services/tts/generated-speech/assemble-plan.js.map +1 -0
  92. package/dist/services/tts/generated-speech/dom/build-dom-plan.d.ts +25 -0
  93. package/dist/services/tts/generated-speech/dom/build-dom-plan.js +66 -0
  94. package/dist/services/tts/generated-speech/dom/build-dom-plan.js.map +1 -0
  95. package/dist/services/tts/generated-speech/dom/to-chunk-inputs.d.ts +19 -0
  96. package/dist/services/tts/generated-speech/dom/to-chunk-inputs.js +71 -0
  97. package/dist/services/tts/generated-speech/dom/to-chunk-inputs.js.map +1 -0
  98. package/dist/services/tts/generated-speech/dom/types.d.ts +37 -0
  99. package/dist/services/tts/generated-speech/dom/types.js +2 -0
  100. package/dist/services/tts/generated-speech/dom/types.js.map +1 -0
  101. package/dist/services/tts/generated-speech/index.d.ts +17 -0
  102. package/dist/services/tts/generated-speech/index.js +17 -0
  103. package/dist/services/tts/generated-speech/index.js.map +1 -0
  104. package/dist/services/tts/generated-speech/math-speech-cache.d.ts +15 -0
  105. package/dist/services/tts/generated-speech/math-speech-cache.js +78 -0
  106. package/dist/services/tts/generated-speech/math-speech-cache.js.map +1 -0
  107. package/dist/services/tts/generated-speech/types.d.ts +104 -0
  108. package/dist/services/tts/generated-speech/types.js +18 -0
  109. package/dist/services/tts/generated-speech/types.js.map +1 -0
  110. package/dist/services/tts/highlight-pipeline/boundary-normalizer.d.ts +2 -0
  111. package/dist/services/tts/highlight-pipeline/boundary-normalizer.js +106 -0
  112. package/dist/services/tts/highlight-pipeline/boundary-normalizer.js.map +1 -0
  113. package/dist/services/tts/highlight-pipeline/create-highlight-plan.d.ts +6 -0
  114. package/dist/services/tts/highlight-pipeline/create-highlight-plan.js +217 -0
  115. package/dist/services/tts/highlight-pipeline/create-highlight-plan.js.map +1 -0
  116. package/dist/services/tts/highlight-pipeline/highlight-policy.d.ts +2 -0
  117. package/dist/services/tts/highlight-pipeline/highlight-policy.js +32 -0
  118. package/dist/services/tts/highlight-pipeline/highlight-policy.js.map +1 -0
  119. package/dist/services/tts/highlight-pipeline/index.d.ts +9 -0
  120. package/dist/services/tts/highlight-pipeline/index.js +9 -0
  121. package/dist/services/tts/highlight-pipeline/index.js.map +1 -0
  122. package/dist/services/tts/highlight-pipeline/math-semantic-resolver.d.ts +3 -0
  123. package/dist/services/tts/highlight-pipeline/math-semantic-resolver.js +32 -0
  124. package/dist/services/tts/highlight-pipeline/math-semantic-resolver.js.map +1 -0
  125. package/dist/services/tts/highlight-pipeline/normalize-speech-chunks.d.ts +29 -0
  126. package/dist/services/tts/highlight-pipeline/normalize-speech-chunks.js +44 -0
  127. package/dist/services/tts/highlight-pipeline/normalize-speech-chunks.js.map +1 -0
  128. package/dist/services/tts/highlight-pipeline/prose-boundary-resolver.d.ts +2 -0
  129. package/dist/services/tts/highlight-pipeline/prose-boundary-resolver.js +20 -0
  130. package/dist/services/tts/highlight-pipeline/prose-boundary-resolver.js.map +1 -0
  131. package/dist/services/tts/highlight-pipeline/readable-region.d.ts +1 -0
  132. package/dist/services/tts/highlight-pipeline/readable-region.js +19 -0
  133. package/dist/services/tts/highlight-pipeline/readable-region.js.map +1 -0
  134. package/dist/services/tts/highlight-pipeline/rendered-math-target-resolver.d.ts +6 -0
  135. package/dist/services/tts/highlight-pipeline/rendered-math-target-resolver.js +198 -0
  136. package/dist/services/tts/highlight-pipeline/rendered-math-target-resolver.js.map +1 -0
  137. package/dist/services/tts/highlight-pipeline/types.d.ts +72 -0
  138. package/dist/services/tts/highlight-pipeline/types.js +2 -0
  139. package/dist/services/tts/highlight-pipeline/types.js.map +1 -0
  140. package/dist/services/tts/highlight-pipeline/visible-map-range.d.ts +2 -0
  141. package/dist/services/tts/highlight-pipeline/visible-map-range.js +22 -0
  142. package/dist/services/tts/highlight-pipeline/visible-map-range.js.map +1 -0
  143. package/dist/services/tts/math-alignment/index.d.ts +30 -0
  144. package/dist/services/tts/math-alignment/index.js +66 -0
  145. package/dist/services/tts/math-alignment/index.js.map +1 -0
  146. package/dist/services/tts/math-alignment/mathml-tokenizer.d.ts +2 -0
  147. package/dist/services/tts/math-alignment/mathml-tokenizer.js +317 -0
  148. package/dist/services/tts/math-alignment/mathml-tokenizer.js.map +1 -0
  149. package/dist/services/tts/math-alignment/range-resolver.d.ts +10 -0
  150. package/dist/services/tts/math-alignment/range-resolver.js +13 -0
  151. package/dist/services/tts/math-alignment/range-resolver.js.map +1 -0
  152. package/dist/services/tts/math-alignment/sequence-aligner.d.ts +7 -0
  153. package/dist/services/tts/math-alignment/sequence-aligner.js +119 -0
  154. package/dist/services/tts/math-alignment/sequence-aligner.js.map +1 -0
  155. package/dist/services/tts/math-alignment/speech-tokenizer.d.ts +31 -0
  156. package/dist/services/tts/math-alignment/speech-tokenizer.js +143 -0
  157. package/dist/services/tts/math-alignment/speech-tokenizer.js.map +1 -0
  158. package/dist/services/tts/math-alignment/types.d.ts +58 -0
  159. package/dist/services/tts/math-alignment/types.js +2 -0
  160. package/dist/services/tts/math-alignment/types.js.map +1 -0
  161. package/dist/services/tts/math-aware-text-processing.d.ts +18 -0
  162. package/dist/services/tts/math-aware-text-processing.js +348 -0
  163. package/dist/services/tts/math-aware-text-processing.js.map +1 -0
  164. package/dist/services/tts/math-speech.d.ts +44 -0
  165. package/dist/services/tts/math-speech.js +147 -0
  166. package/dist/services/tts/math-speech.js.map +1 -0
  167. package/dist/services/tts/mathml-sanitization.d.ts +1 -0
  168. package/dist/services/tts/mathml-sanitization.js +170 -0
  169. package/dist/services/tts/mathml-sanitization.js.map +1 -0
  170. package/dist/services/tts/ssml/spoken-text.d.ts +33 -0
  171. package/dist/services/tts/ssml/spoken-text.js +159 -0
  172. package/dist/services/tts/ssml/spoken-text.js.map +1 -0
  173. package/dist/services/tts/text-processing.d.ts +3 -0
  174. package/dist/services/tts/text-processing.js +30 -4
  175. package/dist/services/tts/text-processing.js.map +1 -1
  176. package/dist/services/tts-runtime-config.d.ts +17 -1
  177. package/dist/services/tts-runtime-config.js +11 -1
  178. package/dist/services/tts-runtime-config.js.map +1 -1
  179. package/dist/tools/registrations/accessibility-tools.js +0 -1
  180. package/dist/tools/registrations/accessibility-tools.js.map +1 -1
  181. package/dist/tools/registrations/calculator.js +41 -2
  182. package/dist/tools/registrations/calculator.js.map +1 -1
  183. package/dist/tools/tool-tag-map.js +0 -1
  184. package/dist/tools/tool-tag-map.js.map +1 -1
  185. package/package.json +8 -11
  186. package/dist/services/PNPToolResolver.d.ts +0 -280
  187. package/dist/services/PNPToolResolver.js +0 -514
  188. package/dist/services/PNPToolResolver.js.map +0 -1
  189. package/dist/services/pnp-provenance.d.ts +0 -166
  190. package/dist/services/pnp-provenance.js +0 -231
  191. package/dist/services/pnp-provenance.js.map +0 -1
package/dist/index.d.ts CHANGED
@@ -12,7 +12,7 @@ export { connectAssessmentToolkitHostRuntimeContext, connectAssessmentToolkitReg
12
12
  export { PIE_INTERNAL_CONTENT_LOADED_EVENT, PIE_INTERNAL_ITEM_SESSION_CHANGED_EVENT, PIE_INTERNAL_ITEM_PLAYER_ERROR_EVENT, PIE_ITEM_SESSION_CHANGED_EVENT, PIE_REGISTER_EVENT, PIE_UNREGISTER_EVENT, type InternalContentLoadedDetail, type InternalItemSessionChangedDetail, type InternalItemPlayerErrorDetail, type ItemSessionChangedDetail, type RuntimeRegistrationDetail, type RuntimeRegistrationKind, } from "./runtime/registration-events.js";
13
13
  export { connectToolRegionScopeContext, connectToolRuntimeContext, connectToolShellContext, createCrossBoundaryEvent, dispatchCrossBoundaryEvent, isContextValueDefined, } from "./runtime/tool-host-contract.js";
14
14
  export type { AccessibilityCatalogResolverApi, ElementToolStateStoreApi, HighlightCoordinatorApi, I18nServiceApi, ThemeProviderApi, ToolCoordinatorApi, ToolkitCoordinatorApi, TtsServiceApi, ToolState, } from "./services/interfaces.js";
15
- export type { CatalogLookupOptions, CatalogStatistics, CatalogType, ResolvedCatalog, } from "./services/AccessibilityCatalogResolver.js";
15
+ export type { CatalogLookupContext, CatalogLookupOptions, CatalogOwnerContext, CatalogOwnerKind, CatalogStatistics, CatalogType, ResolvedCatalog, } from "./services/AccessibilityCatalogResolver.js";
16
16
  export { AccessibilityCatalogResolver } from "./services/AccessibilityCatalogResolver.js";
17
17
  export { ContextVariableStore } from "./services/ContextVariableStore.js";
18
18
  export { ElementToolStateStore } from "./services/ElementToolStateStore.js";
@@ -32,10 +32,6 @@ export { createToolsConfig } from "./services/create-tools-config.js";
32
32
  export { DEFAULT_PERSONAL_NEEDS_PROFILE, createDefaultPersonalNeedsProfile, } from "./services/defaultPersonalNeedsProfile.js";
33
33
  export type { ToolComponentFactory, ToolComponentFactoryMap, ToolComponentOverrides, ToolTagMap, } from "./tools/tool-tag-map.js";
34
34
  export { createToolElement, DEFAULT_TOOL_TAG_MAP, resolveToolTag, toToolIdFromTag, } from "./tools/tool-tag-map.js";
35
- export type { ResolvedToolConfig, ToolResolutionResult, } from "./services/PNPToolResolver.js";
36
- export { PnpToolResolver } from "./services/PNPToolResolver.js";
37
- export type { FeatureResolutionTrail, PnpResolutionProvenance, ResolutionDecision, } from "./services/pnp-provenance.js";
38
- export { formatProvenanceAsJSON, formatProvenanceAsMarkdown, getFeatureExplanation, PnpProvenanceBuilder, } from "./services/pnp-provenance.js";
39
35
  export { ALL_STANDARD_ACCESS_FEATURES, EXAMPLE_PNP_CONFIGURATIONS, getFeatureCategory, getFeaturesInCategory, isStandardAccessFeature, QTI_STANDARD_ACCESS_FEATURES, } from "./services/pnp-standard-features.js";
40
36
  export type { ExtractionResult } from "./services/SSMLExtractor.js";
41
37
  export { SSMLExtractor } from "./services/SSMLExtractor.js";
@@ -51,7 +47,7 @@ export type { FrameworkErrorListener, } from "./services/framework-error-bus.js"
51
47
  export type { ToolConfigDiagnostic, ToolConfigDiagnosticSeverity, ToolConfigStrictness, ToolConfigValidationOptions, ToolConfigValidationResult, } from "./services/tool-config-validation.js";
52
48
  export type { ToolbarButtonItem, ToolbarItem, ToolbarItemBase, ToolbarLinkItem, } from "./services/toolbar-items.js";
53
49
  export { isExternalIconUrl, isInlineSvgIcon, isToolbarLinkItem, isValidToolbarItemShape, } from "./services/toolbar-items.js";
54
- export { normalizeToolsConfig, normalizeToolAlias, normalizeToolList, parseToolList, resolveToolsForLevel, } from "./services/tools-config-normalizer.js";
50
+ export { normalizeToolsConfig, normalizeToolAlias, normalizeToolList, parseToolList, } from "./services/tools-config-normalizer.js";
55
51
  export { frameworkErrorFromToolConfigValidation, normalizeAndValidateToolsConfig, } from "./services/tool-config-validation.js";
56
52
  export type { ParsedToolInstanceId, ToolScopeLevel, } from "./services/tool-instance-id.js";
57
53
  export { createScopedToolId, parseScopedToolId, toOverlayToolId, } from "./services/tool-instance-id.js";
@@ -59,6 +55,7 @@ export type { TTSConfig } from "./services/TTSService.js";
59
55
  export { PlaybackState, TTSService } from "./services/TTSService.js";
60
56
  export { PIE_TTS_CONTROL_HANDOFF_EVENT, type TTSControlHandoffDetail, } from "./services/tts-control-events.js";
61
57
  export { BrowserTTSProvider } from "./services/tts/browser-provider.js";
58
+ export type { SREMathSpeechOptions } from "./services/tts/math-speech.js";
62
59
  export type { TTSHostToolbarLayout, TTSLayoutMode, TTSRuntimeSettings, } from "./services/tts-runtime-config.js";
63
60
  export { DEFAULT_TTS_SPEED_OPTIONS, formatTTSSpeedOptionsAsText, normalizeTTSLayoutMode, normalizeTTSSpeedOptions, parseTTSSpeedOptionsFromText, resolveTTSHostToolbarLayout, resolveTTSLayoutMode, resolveTTSRuntimeSettings, } from "./services/tts-runtime-config.js";
64
61
  export type { ITTSProvider, ITTSProviderImplementation, TTSSpeechSegment, TTSFeature, TTSProviderCapabilities, } from "@pie-players/pie-tts";
package/dist/index.js CHANGED
@@ -24,8 +24,6 @@ export { DEFAULT_TOOL_PLACEMENT, DEFAULT_TOOL_ORDER, createPackagedToolRegistry,
24
24
  export { createToolsConfig } from "./services/create-tools-config.js";
25
25
  export { DEFAULT_PERSONAL_NEEDS_PROFILE, createDefaultPersonalNeedsProfile, } from "./services/defaultPersonalNeedsProfile.js";
26
26
  export { createToolElement, DEFAULT_TOOL_TAG_MAP, resolveToolTag, toToolIdFromTag, } from "./tools/tool-tag-map.js";
27
- export { PnpToolResolver } from "./services/PNPToolResolver.js";
28
- export { formatProvenanceAsJSON, formatProvenanceAsMarkdown, getFeatureExplanation, PnpProvenanceBuilder, } from "./services/pnp-provenance.js";
29
27
  // QTI 3.0 Standard Access Features
30
28
  export { ALL_STANDARD_ACCESS_FEATURES, EXAMPLE_PNP_CONFIGURATIONS, getFeatureCategory, getFeaturesInCategory, isStandardAccessFeature, QTI_STANDARD_ACCESS_FEATURES, } from "./services/pnp-standard-features.js";
31
29
  export { SSMLExtractor } from "./services/SSMLExtractor.js";
@@ -35,7 +33,7 @@ export { ToolCoordinator, ZIndexLayer } from "./services/ToolCoordinator.js";
35
33
  export { ToolkitCoordinator } from "./services/ToolkitCoordinator.js";
36
34
  export { formatFrameworkErrorForConsole, frameworkErrorFromToolConfigDiagnostics, frameworkErrorFromUnknown, toFrameworkErrorModel, } from "./services/framework-error.js";
37
35
  export { isExternalIconUrl, isInlineSvgIcon, isToolbarLinkItem, isValidToolbarItemShape, } from "./services/toolbar-items.js";
38
- export { normalizeToolsConfig, normalizeToolAlias, normalizeToolList, parseToolList, resolveToolsForLevel, } from "./services/tools-config-normalizer.js";
36
+ export { normalizeToolsConfig, normalizeToolAlias, normalizeToolList, parseToolList, } from "./services/tools-config-normalizer.js";
39
37
  export { frameworkErrorFromToolConfigValidation, normalizeAndValidateToolsConfig, } from "./services/tool-config-validation.js";
40
38
  export { createScopedToolId, parseScopedToolId, toOverlayToolId, } from "./services/tool-instance-id.js";
41
39
  export { PlaybackState, TTSService } from "./services/TTSService.js";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAeH,OAAO,EACN,mCAAmC,EACnC,mCAAmC,EACnC,+BAA+B,EAC/B,6BAA6B,GAC7B,MAAM,yCAAyC,CAAC;AACjD,OAAO,EACN,0CAA0C,EAC1C,0CAA0C,EAC1C,sCAAsC,EACtC,oCAAoC,GACpC,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EACN,iCAAiC,EACjC,uCAAuC,EACvC,oCAAoC,EACpC,8BAA8B,EAC9B,kBAAkB,EAClB,oBAAoB,GAOpB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACN,6BAA6B,EAC7B,yBAAyB,EACzB,uBAAuB,EACvB,wBAAwB,EACxB,0BAA0B,EAC1B,qBAAqB,GACrB,MAAM,iCAAiC,CAAC;AA6BzC,OAAO,EAAE,4BAA4B,EAAE,MAAM,4CAA4C,CAAC;AAC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BAA8B,EAC9B,qBAAqB,EACrB,qBAAqB,EACrB,yBAAyB,EACzB,oBAAoB,GACpB,MAAM,gCAAgC,CAAC;AAQxC,OAAO,EACN,8BAA8B,EAC9B,+CAA+C,EAC/C,+BAA+B,EAC/B,oBAAoB,GACpB,MAAM,wDAAwD,CAAC;AAEhE,qEAAqE;AAErE,+EAA+E;AAC/E,oBAAoB;AACpB,+EAA+E;AAE/E,4FAA4F;AAC5F,8FAA8F;AAC9F,qGAAqG","sourcesContent":["/**\n * PIE Assessment Toolkit\n *\n * Independent, composable services for coordinating tools, accommodations,\n * and item players in assessment applications.\n *\n * @packageDocumentation\n */\n\n// ============================================================================\n// Core Infrastructure\n// ============================================================================\n\nexport type {\n\tAssessmentToolkitHostRuntimeContext,\n\tAssessmentToolkitRegionScopeContext,\n\tAssessmentToolkitRuntimeContext,\n\tAssessmentToolkitShellContext,\n\tItemPlayerConfig,\n\tItemPlayerType,\n\tShellContextKind,\n} from \"./context/assessment-toolkit-context.js\";\nexport {\n\tassessmentToolkitHostRuntimeContext,\n\tassessmentToolkitRegionScopeContext,\n\tassessmentToolkitRuntimeContext,\n\tassessmentToolkitShellContext,\n} from \"./context/assessment-toolkit-context.js\";\nexport {\n\tconnectAssessmentToolkitHostRuntimeContext,\n\tconnectAssessmentToolkitRegionScopeContext,\n\tconnectAssessmentToolkitRuntimeContext,\n\tconnectAssessmentToolkitShellContext,\n} from \"./context/runtime-context-consumer.js\";\nexport {\n\tPIE_INTERNAL_CONTENT_LOADED_EVENT,\n\tPIE_INTERNAL_ITEM_SESSION_CHANGED_EVENT,\n\tPIE_INTERNAL_ITEM_PLAYER_ERROR_EVENT,\n\tPIE_ITEM_SESSION_CHANGED_EVENT,\n\tPIE_REGISTER_EVENT,\n\tPIE_UNREGISTER_EVENT,\n\ttype InternalContentLoadedDetail,\n\ttype InternalItemSessionChangedDetail,\n\ttype InternalItemPlayerErrorDetail,\n\ttype ItemSessionChangedDetail,\n\ttype RuntimeRegistrationDetail,\n\ttype RuntimeRegistrationKind,\n} from \"./runtime/registration-events.js\";\nexport {\n\tconnectToolRegionScopeContext,\n\tconnectToolRuntimeContext,\n\tconnectToolShellContext,\n\tcreateCrossBoundaryEvent,\n\tdispatchCrossBoundaryEvent,\n\tisContextValueDefined,\n} from \"./runtime/tool-host-contract.js\";\n\n// ============================================================================\n// Service Interfaces\n// ============================================================================\n\nexport type {\n\tAccessibilityCatalogResolverApi,\n\tElementToolStateStoreApi,\n\tHighlightCoordinatorApi,\n\tI18nServiceApi,\n\tThemeProviderApi,\n\tToolCoordinatorApi,\n\tToolkitCoordinatorApi,\n\tTtsServiceApi,\n\tToolState,\n} from \"./services/interfaces.js\";\n\n// ============================================================================\n// Toolkit Services\n// ============================================================================\n\n// Accessibility Catalog Resolver (QTI 3.0 Accessibility Catalogs)\nexport type {\n\tCatalogLookupOptions,\n\tCatalogStatistics,\n\tCatalogType,\n\tResolvedCatalog,\n} from \"./services/AccessibilityCatalogResolver.js\";\nexport { AccessibilityCatalogResolver } from \"./services/AccessibilityCatalogResolver.js\";\n// Context Variable Store (QTI 3.0 Context Declarations)\nexport { ContextVariableStore } from \"./services/ContextVariableStore.js\";\n// Element Tool State Store (Element-level ephemeral tool state)\nexport { ElementToolStateStore } from \"./services/ElementToolStateStore.js\";\n// Highlight Coordinator\nexport type { Annotation } from \"./services/HighlightCoordinator.js\";\nexport {\n\tHighlightColor,\n\tHighlightCoordinator,\n\tHighlightType,\n} from \"./services/HighlightCoordinator.js\";\n// Range Serializer (for annotation persistence)\nexport type { SerializedRange } from \"./services/RangeSerializer.js\";\nexport { RangeSerializer } from \"./services/RangeSerializer.js\";\n// I18n Service\nexport type {\n\tI18nConfig,\n\tPluralTranslation,\n\tTranslationBundle,\n} from \"./services/I18nService.js\";\nexport { I18nService } from \"./services/I18nService.js\";\n// Tool Registry (Registry-based tool system)\nexport type {\n\tResolvedToolContext,\n\tToolbarContext,\n\tToolContextResolver,\n\tToolContextResolverContext,\n\tToolContextResolverMap,\n\tToolContextResolverResult,\n\tToolModuleLoader,\n\tToolToolbarButtonDefinition,\n\tToolToolbarRenderResult,\n\tToolRegistration,\n} from \"./services/ToolRegistry.js\";\nexport { ToolRegistry } from \"./services/ToolRegistry.js\";\nexport type {\n\tAssessmentToolContext,\n\tBaseToolContext,\n\tElementToolContext,\n\tItemToolContext,\n\tPassageToolContext,\n\tRubricToolContext,\n\tSectionToolContext,\n\tToolContext,\n\tToolLevel,\n} from \"./services/tool-context.js\";\nexport {\n\textractTextContent,\n\thasChoiceInteraction,\n\thasMathContent,\n\thasReadableText,\n\tisAssessmentContext,\n\tisElementContext,\n\tisItemContext,\n\tisPassageContext,\n\tisRubricContext,\n\tisSectionContext,\n} from \"./services/tool-context.js\";\nexport {\n\tDEFAULT_TOOL_PLACEMENT,\n\tDEFAULT_TOOL_ORDER,\n\tcreatePackagedToolRegistry,\n\tPACKAGED_TOOL_PLACEMENT,\n\tregisterPackagedTools,\n} from \"./services/createDefaultToolRegistry.js\";\nexport type { CreateToolsConfigArgs } from \"./services/create-tools-config.js\";\nexport { createToolsConfig } from \"./services/create-tools-config.js\";\nexport {\n\tDEFAULT_PERSONAL_NEEDS_PROFILE,\n\tcreateDefaultPersonalNeedsProfile,\n} from \"./services/defaultPersonalNeedsProfile.js\";\nexport type {\n\tToolComponentFactory,\n\tToolComponentFactoryMap,\n\tToolComponentOverrides,\n\tToolTagMap,\n} from \"./tools/tool-tag-map.js\";\nexport {\n\tcreateToolElement,\n\tDEFAULT_TOOL_TAG_MAP,\n\tresolveToolTag,\n\ttoToolIdFromTag,\n} from \"./tools/tool-tag-map.js\";\n// PNP Tool Resolution (QTI 3.0 Native)\nexport type {\n\tResolvedToolConfig,\n\tToolResolutionResult,\n} from \"./services/PNPToolResolver.js\";\nexport { PnpToolResolver } from \"./services/PNPToolResolver.js\";\n// PNP Provenance Tracking\nexport type {\n\tFeatureResolutionTrail,\n\tPnpResolutionProvenance,\n\tResolutionDecision,\n} from \"./services/pnp-provenance.js\";\nexport {\n\tformatProvenanceAsJSON,\n\tformatProvenanceAsMarkdown,\n\tgetFeatureExplanation,\n\tPnpProvenanceBuilder,\n} from \"./services/pnp-provenance.js\";\n// QTI 3.0 Standard Access Features\nexport {\n\tALL_STANDARD_ACCESS_FEATURES,\n\tEXAMPLE_PNP_CONFIGURATIONS,\n\tgetFeatureCategory,\n\tgetFeaturesInCategory,\n\tisStandardAccessFeature,\n\tQTI_STANDARD_ACCESS_FEATURES,\n} from \"./services/pnp-standard-features.js\";\n// SSML Extractor (Auto-generates catalogs from embedded SSML)\nexport type { ExtractionResult } from \"./services/SSMLExtractor.js\";\nexport { SSMLExtractor } from \"./services/SSMLExtractor.js\";\n// Theme Provider\nexport type { FontSize, ThemeConfig } from \"./services/ThemeProvider.js\";\nexport { ThemeProvider } from \"./services/ThemeProvider.js\";\n// Tool Coordinator\nexport { ToolCoordinator, ZIndexLayer } from \"./services/ToolCoordinator.js\";\n// Toolkit Coordinator (Centralized service management)\nexport type {\n\tAnswerEliminatorToolConfig,\n\tProviderLifecycleContext,\n\tSectionControllerContext,\n\tSectionControllerEvent,\n\tSectionControllerEventType,\n\tSectionItemEvent,\n\tSectionItemEventType,\n\tSectionControllerFactoryDefaults,\n\tSectionControllerHandle,\n\tSectionControllerKey,\n\tSectionScopedEvent,\n\tSectionScopedEventType,\n\tSectionSessionPersistenceConfig,\n\tSectionItemEventSubscriptionArgs,\n\tSectionScopedEventSubscriptionArgs,\n\tSectionEventSubscriptionArgs,\n\tSectionSessionPersistenceStrategy,\n\tSectionControllerLoadedRenderable,\n\tSectionControllerRuntimeState,\n\tSectionControllerSessionState,\n\tSectionPersistenceFactoryDefaults,\n\tToolConfig,\n\tToolkitCoordinatorConfig,\n\tToolkitCoordinatorHooks,\n\tToolkitErrorContext,\n\tToolkitInitStatus,\n\tToolkitServiceBundle,\n\tToolkitToolsConfig,\n\tTTSToolConfig,\n} from \"./services/ToolkitCoordinator.js\";\nexport { ToolkitCoordinator } from \"./services/ToolkitCoordinator.js\";\nexport type {\n\tCanonicalToolsConfig,\n\tToolPlacementConfig,\n\tToolPlacementLevel,\n\tToolPolicyConfig,\n\tToolProvidersConfig,\n} from \"./services/tools-config-normalizer.js\";\nexport type {\n\tFrameworkErrorKind,\n\tFrameworkErrorModel,\n\tFrameworkErrorSeverity,\n} from \"./services/framework-error.js\";\nexport {\n\tformatFrameworkErrorForConsole,\n\tframeworkErrorFromToolConfigDiagnostics,\n\tframeworkErrorFromUnknown,\n\ttoFrameworkErrorModel,\n} from \"./services/framework-error.js\";\nexport type {\n\tFrameworkErrorListener,\n} from \"./services/framework-error-bus.js\";\nexport type {\n\tToolConfigDiagnostic,\n\tToolConfigDiagnosticSeverity,\n\tToolConfigStrictness,\n\tToolConfigValidationOptions,\n\tToolConfigValidationResult,\n} from \"./services/tool-config-validation.js\";\nexport type {\n\tToolbarButtonItem,\n\tToolbarItem,\n\tToolbarItemBase,\n\tToolbarLinkItem,\n} from \"./services/toolbar-items.js\";\nexport {\n\tisExternalIconUrl,\n\tisInlineSvgIcon,\n\tisToolbarLinkItem,\n\tisValidToolbarItemShape,\n} from \"./services/toolbar-items.js\";\nexport {\n\tnormalizeToolsConfig,\n\tnormalizeToolAlias,\n\tnormalizeToolList,\n\tparseToolList,\n\tresolveToolsForLevel,\n} from \"./services/tools-config-normalizer.js\";\nexport {\n\tframeworkErrorFromToolConfigValidation,\n\tnormalizeAndValidateToolsConfig,\n} from \"./services/tool-config-validation.js\";\nexport type {\n\tParsedToolInstanceId,\n\tToolScopeLevel,\n} from \"./services/tool-instance-id.js\";\nexport {\n\tcreateScopedToolId,\n\tparseScopedToolId,\n\ttoOverlayToolId,\n} from \"./services/tool-instance-id.js\";\n// Text-to-Speech Service\nexport type { TTSConfig } from \"./services/TTSService.js\";\nexport { PlaybackState, TTSService } from \"./services/TTSService.js\";\nexport {\n\tPIE_TTS_CONTROL_HANDOFF_EVENT,\n\ttype TTSControlHandoffDetail,\n} from \"./services/tts-control-events.js\";\nexport { BrowserTTSProvider } from \"./services/tts/browser-provider.js\";\nexport type {\n\tTTSHostToolbarLayout,\n\tTTSLayoutMode,\n\tTTSRuntimeSettings,\n} from \"./services/tts-runtime-config.js\";\nexport {\n\tDEFAULT_TTS_SPEED_OPTIONS,\n\tformatTTSSpeedOptionsAsText,\n\tnormalizeTTSLayoutMode,\n\tnormalizeTTSSpeedOptions,\n\tparseTTSSpeedOptionsFromText,\n\tresolveTTSHostToolbarLayout,\n\tresolveTTSLayoutMode,\n\tresolveTTSRuntimeSettings,\n} from \"./services/tts-runtime-config.js\";\n// TTS Provider System\nexport type {\n\tITTSProvider,\n\tITTSProviderImplementation,\n\tTTSSpeechSegment,\n\tTTSFeature,\n\tTTSProviderCapabilities,\n} from \"@pie-players/pie-tts\";\n\n// ============================================================================\n// Item loading (client-resolvable default; optional backend hook)\n// ============================================================================\n\nexport type {\n\tCreateLoadItemOptions,\n\tLoadItem,\n\tLoadItemOptions,\n} from \"./item-loader.js\";\nexport {\n\tcreateFetchItemLoader,\n\tcreateLoadItem,\n\tItemLoadError,\n} from \"./item-loader.js\";\n\n// ============================================================================\n// Attempt Session\n// ============================================================================\n\nexport type {\n\tStorageLike,\n\tTestAttemptItemSession,\n\tTestAttemptSession,\n\tTestAttemptSessionNavigationState,\n\tTestAttemptSessionRealization,\n} from \"./attempt/TestSession.js\";\nexport {\n\tcreateMemoryStorage,\n\tcreateTestAttemptSessionIdentifier,\n\tcreateNewTestAttemptSession,\n\tgetBrowserLocalStorage,\n\tgetOrCreateAnonymousDeviceId,\n\tgetTestAttemptSessionStorageKey,\n\tloadTestAttemptSession,\n\tsaveTestAttemptSession,\n\tsetCurrentPosition,\n\tupsertItemSessionFromPieSessionChange,\n\tupsertVisitedItem,\n} from \"./attempt/TestSession.js\";\nexport type {\n\tAssessmentSession,\n\tAssessmentSectionSessionState,\n\tAssessmentSessionNavigationState,\n\tAssessmentSessionRealization,\n} from \"./attempt/AssessmentSession.js\";\nexport {\n\tcreateNewAssessmentSession,\n\tgetAssessmentSessionStorageKey,\n\tloadAssessmentSession,\n\tsaveAssessmentSession,\n\tsetCurrentSectionPosition,\n\tupsertSectionSession,\n} from \"./attempt/AssessmentSession.js\";\nexport type {\n\tActivitySessionPatchPayload,\n\tMapActivityToTestAttemptSessionArgs,\n\tPieBackendActivityDefinition,\n\tPieBackendActivityItemRef,\n\tPieBackendActivitySession,\n} from \"./attempt/adapters/activity-to-test-attempt-session.js\";\nexport {\n\tbuildActivitySessionItemUpdate,\n\tbuildActivitySessionPatchFromTestAttemptSession,\n\tmapActivityToTestAttemptSession,\n\ttoItemSessionsRecord,\n} from \"./attempt/adapters/activity-to-test-attempt-session.js\";\n\n// Section Player - Use @pie-players/pie-section-player web component\n\n// ============================================================================\n// Shared Components\n// ============================================================================\n\n// ItemToolBar custom element registration helper is exported via package.json exports field\n// Import using: import '@pie-players/pie-assessment-toolkit/components/item-toolbar-element';\n// PieAssessmentToolkit custom element registration helper is exported via package.json exports field\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAeH,OAAO,EACN,mCAAmC,EACnC,mCAAmC,EACnC,+BAA+B,EAC/B,6BAA6B,GAC7B,MAAM,yCAAyC,CAAC;AACjD,OAAO,EACN,0CAA0C,EAC1C,0CAA0C,EAC1C,sCAAsC,EACtC,oCAAoC,GACpC,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EACN,iCAAiC,EACjC,uCAAuC,EACvC,oCAAoC,EACpC,8BAA8B,EAC9B,kBAAkB,EAClB,oBAAoB,GAOpB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACN,6BAA6B,EAC7B,yBAAyB,EACzB,uBAAuB,EACvB,wBAAwB,EACxB,0BAA0B,EAC1B,qBAAqB,GACrB,MAAM,iCAAiC,CAAC;AAgCzC,OAAO,EAAE,4BAA4B,EAAE,MAAM,4CAA4C,CAAC;AAC1F,wDAAwD;AACxD,OAAO,EAAE,oBAAoB,EAAE,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AAErE,+EAA+E;AAC/E,oBAAoB;AACpB,+EAA+E;AAE/E,4FAA4F;AAC5F,8FAA8F;AAC9F,qGAAqG","sourcesContent":["/**\n * PIE Assessment Toolkit\n *\n * Independent, composable services for coordinating tools, accommodations,\n * and item players in assessment applications.\n *\n * @packageDocumentation\n */\n\n// ============================================================================\n// Core Infrastructure\n// ============================================================================\n\nexport type {\n\tAssessmentToolkitHostRuntimeContext,\n\tAssessmentToolkitRegionScopeContext,\n\tAssessmentToolkitRuntimeContext,\n\tAssessmentToolkitShellContext,\n\tItemPlayerConfig,\n\tItemPlayerType,\n\tShellContextKind,\n} from \"./context/assessment-toolkit-context.js\";\nexport {\n\tassessmentToolkitHostRuntimeContext,\n\tassessmentToolkitRegionScopeContext,\n\tassessmentToolkitRuntimeContext,\n\tassessmentToolkitShellContext,\n} from \"./context/assessment-toolkit-context.js\";\nexport {\n\tconnectAssessmentToolkitHostRuntimeContext,\n\tconnectAssessmentToolkitRegionScopeContext,\n\tconnectAssessmentToolkitRuntimeContext,\n\tconnectAssessmentToolkitShellContext,\n} from \"./context/runtime-context-consumer.js\";\nexport {\n\tPIE_INTERNAL_CONTENT_LOADED_EVENT,\n\tPIE_INTERNAL_ITEM_SESSION_CHANGED_EVENT,\n\tPIE_INTERNAL_ITEM_PLAYER_ERROR_EVENT,\n\tPIE_ITEM_SESSION_CHANGED_EVENT,\n\tPIE_REGISTER_EVENT,\n\tPIE_UNREGISTER_EVENT,\n\ttype InternalContentLoadedDetail,\n\ttype InternalItemSessionChangedDetail,\n\ttype InternalItemPlayerErrorDetail,\n\ttype ItemSessionChangedDetail,\n\ttype RuntimeRegistrationDetail,\n\ttype RuntimeRegistrationKind,\n} from \"./runtime/registration-events.js\";\nexport {\n\tconnectToolRegionScopeContext,\n\tconnectToolRuntimeContext,\n\tconnectToolShellContext,\n\tcreateCrossBoundaryEvent,\n\tdispatchCrossBoundaryEvent,\n\tisContextValueDefined,\n} from \"./runtime/tool-host-contract.js\";\n\n// ============================================================================\n// Service Interfaces\n// ============================================================================\n\nexport type {\n\tAccessibilityCatalogResolverApi,\n\tElementToolStateStoreApi,\n\tHighlightCoordinatorApi,\n\tI18nServiceApi,\n\tThemeProviderApi,\n\tToolCoordinatorApi,\n\tToolkitCoordinatorApi,\n\tTtsServiceApi,\n\tToolState,\n} from \"./services/interfaces.js\";\n\n// ============================================================================\n// Toolkit Services\n// ============================================================================\n\n// Accessibility Catalog Resolver (QTI 3.0 Accessibility Catalogs)\nexport type {\n\tCatalogLookupContext,\n\tCatalogLookupOptions,\n\tCatalogOwnerContext,\n\tCatalogOwnerKind,\n\tCatalogStatistics,\n\tCatalogType,\n\tResolvedCatalog,\n} from \"./services/AccessibilityCatalogResolver.js\";\nexport { AccessibilityCatalogResolver } from \"./services/AccessibilityCatalogResolver.js\";\n// Context Variable Store (QTI 3.0 Context Declarations)\nexport { ContextVariableStore } from \"./services/ContextVariableStore.js\";\n// Element Tool State Store (Element-level ephemeral tool state)\nexport { ElementToolStateStore } from \"./services/ElementToolStateStore.js\";\n// Highlight Coordinator\nexport type { Annotation } from \"./services/HighlightCoordinator.js\";\nexport {\n\tHighlightColor,\n\tHighlightCoordinator,\n\tHighlightType,\n} from \"./services/HighlightCoordinator.js\";\n// Range Serializer (for annotation persistence)\nexport type { SerializedRange } from \"./services/RangeSerializer.js\";\nexport { RangeSerializer } from \"./services/RangeSerializer.js\";\n// I18n Service\nexport type {\n\tI18nConfig,\n\tPluralTranslation,\n\tTranslationBundle,\n} from \"./services/I18nService.js\";\nexport { I18nService } from \"./services/I18nService.js\";\n// Tool Registry (Registry-based tool system)\nexport type {\n\tResolvedToolContext,\n\tToolbarContext,\n\tToolContextResolver,\n\tToolContextResolverContext,\n\tToolContextResolverMap,\n\tToolContextResolverResult,\n\tToolModuleLoader,\n\tToolToolbarButtonDefinition,\n\tToolToolbarRenderResult,\n\tToolRegistration,\n} from \"./services/ToolRegistry.js\";\nexport { ToolRegistry } from \"./services/ToolRegistry.js\";\nexport type {\n\tAssessmentToolContext,\n\tBaseToolContext,\n\tElementToolContext,\n\tItemToolContext,\n\tPassageToolContext,\n\tRubricToolContext,\n\tSectionToolContext,\n\tToolContext,\n\tToolLevel,\n} from \"./services/tool-context.js\";\nexport {\n\textractTextContent,\n\thasChoiceInteraction,\n\thasMathContent,\n\thasReadableText,\n\tisAssessmentContext,\n\tisElementContext,\n\tisItemContext,\n\tisPassageContext,\n\tisRubricContext,\n\tisSectionContext,\n} from \"./services/tool-context.js\";\nexport {\n\tDEFAULT_TOOL_PLACEMENT,\n\tDEFAULT_TOOL_ORDER,\n\tcreatePackagedToolRegistry,\n\tPACKAGED_TOOL_PLACEMENT,\n\tregisterPackagedTools,\n} from \"./services/createDefaultToolRegistry.js\";\nexport type { CreateToolsConfigArgs } from \"./services/create-tools-config.js\";\nexport { createToolsConfig } from \"./services/create-tools-config.js\";\nexport {\n\tDEFAULT_PERSONAL_NEEDS_PROFILE,\n\tcreateDefaultPersonalNeedsProfile,\n} from \"./services/defaultPersonalNeedsProfile.js\";\nexport type {\n\tToolComponentFactory,\n\tToolComponentFactoryMap,\n\tToolComponentOverrides,\n\tToolTagMap,\n} from \"./tools/tool-tag-map.js\";\nexport {\n\tcreateToolElement,\n\tDEFAULT_TOOL_TAG_MAP,\n\tresolveToolTag,\n\ttoToolIdFromTag,\n} from \"./tools/tool-tag-map.js\";\n// QTI 3.0 Standard Access Features\nexport {\n\tALL_STANDARD_ACCESS_FEATURES,\n\tEXAMPLE_PNP_CONFIGURATIONS,\n\tgetFeatureCategory,\n\tgetFeaturesInCategory,\n\tisStandardAccessFeature,\n\tQTI_STANDARD_ACCESS_FEATURES,\n} from \"./services/pnp-standard-features.js\";\n// SSML Extractor (Auto-generates catalogs from embedded SSML)\nexport type { ExtractionResult } from \"./services/SSMLExtractor.js\";\nexport { SSMLExtractor } from \"./services/SSMLExtractor.js\";\n// Theme Provider\nexport type { FontSize, ThemeConfig } from \"./services/ThemeProvider.js\";\nexport { ThemeProvider } from \"./services/ThemeProvider.js\";\n// Tool Coordinator\nexport { ToolCoordinator, ZIndexLayer } from \"./services/ToolCoordinator.js\";\n// Toolkit Coordinator (Centralized service management)\nexport type {\n\tAnswerEliminatorToolConfig,\n\tProviderLifecycleContext,\n\tSectionControllerContext,\n\tSectionControllerEvent,\n\tSectionControllerEventType,\n\tSectionItemEvent,\n\tSectionItemEventType,\n\tSectionControllerFactoryDefaults,\n\tSectionControllerHandle,\n\tSectionControllerKey,\n\tSectionScopedEvent,\n\tSectionScopedEventType,\n\tSectionSessionPersistenceConfig,\n\tSectionItemEventSubscriptionArgs,\n\tSectionScopedEventSubscriptionArgs,\n\tSectionEventSubscriptionArgs,\n\tSectionSessionPersistenceStrategy,\n\tSectionControllerLoadedRenderable,\n\tSectionControllerRuntimeState,\n\tSectionControllerSessionState,\n\tSectionPersistenceFactoryDefaults,\n\tToolConfig,\n\tToolkitCoordinatorConfig,\n\tToolkitCoordinatorHooks,\n\tToolkitErrorContext,\n\tToolkitInitStatus,\n\tToolkitServiceBundle,\n\tToolkitToolsConfig,\n\tTTSToolConfig,\n} from \"./services/ToolkitCoordinator.js\";\nexport { ToolkitCoordinator } from \"./services/ToolkitCoordinator.js\";\nexport type {\n\tCanonicalToolsConfig,\n\tToolPlacementConfig,\n\tToolPlacementLevel,\n\tToolPolicyConfig,\n\tToolProvidersConfig,\n} from \"./services/tools-config-normalizer.js\";\nexport type {\n\tFrameworkErrorKind,\n\tFrameworkErrorModel,\n\tFrameworkErrorSeverity,\n} from \"./services/framework-error.js\";\nexport {\n\tformatFrameworkErrorForConsole,\n\tframeworkErrorFromToolConfigDiagnostics,\n\tframeworkErrorFromUnknown,\n\ttoFrameworkErrorModel,\n} from \"./services/framework-error.js\";\nexport type {\n\tFrameworkErrorListener,\n} from \"./services/framework-error-bus.js\";\nexport type {\n\tToolConfigDiagnostic,\n\tToolConfigDiagnosticSeverity,\n\tToolConfigStrictness,\n\tToolConfigValidationOptions,\n\tToolConfigValidationResult,\n} from \"./services/tool-config-validation.js\";\nexport type {\n\tToolbarButtonItem,\n\tToolbarItem,\n\tToolbarItemBase,\n\tToolbarLinkItem,\n} from \"./services/toolbar-items.js\";\nexport {\n\tisExternalIconUrl,\n\tisInlineSvgIcon,\n\tisToolbarLinkItem,\n\tisValidToolbarItemShape,\n} from \"./services/toolbar-items.js\";\nexport {\n\tnormalizeToolsConfig,\n\tnormalizeToolAlias,\n\tnormalizeToolList,\n\tparseToolList,\n} from \"./services/tools-config-normalizer.js\";\nexport {\n\tframeworkErrorFromToolConfigValidation,\n\tnormalizeAndValidateToolsConfig,\n} from \"./services/tool-config-validation.js\";\nexport type {\n\tParsedToolInstanceId,\n\tToolScopeLevel,\n} from \"./services/tool-instance-id.js\";\nexport {\n\tcreateScopedToolId,\n\tparseScopedToolId,\n\ttoOverlayToolId,\n} from \"./services/tool-instance-id.js\";\n// Text-to-Speech Service\nexport type { TTSConfig } from \"./services/TTSService.js\";\nexport { PlaybackState, TTSService } from \"./services/TTSService.js\";\nexport {\n\tPIE_TTS_CONTROL_HANDOFF_EVENT,\n\ttype TTSControlHandoffDetail,\n} from \"./services/tts-control-events.js\";\nexport { BrowserTTSProvider } from \"./services/tts/browser-provider.js\";\nexport type { SREMathSpeechOptions } from \"./services/tts/math-speech.js\";\nexport type {\n\tTTSHostToolbarLayout,\n\tTTSLayoutMode,\n\tTTSRuntimeSettings,\n} from \"./services/tts-runtime-config.js\";\nexport {\n\tDEFAULT_TTS_SPEED_OPTIONS,\n\tformatTTSSpeedOptionsAsText,\n\tnormalizeTTSLayoutMode,\n\tnormalizeTTSSpeedOptions,\n\tparseTTSSpeedOptionsFromText,\n\tresolveTTSHostToolbarLayout,\n\tresolveTTSLayoutMode,\n\tresolveTTSRuntimeSettings,\n} from \"./services/tts-runtime-config.js\";\n// TTS Provider System\nexport type {\n\tITTSProvider,\n\tITTSProviderImplementation,\n\tTTSSpeechSegment,\n\tTTSFeature,\n\tTTSProviderCapabilities,\n} from \"@pie-players/pie-tts\";\n\n// ============================================================================\n// Item loading (client-resolvable default; optional backend hook)\n// ============================================================================\n\nexport type {\n\tCreateLoadItemOptions,\n\tLoadItem,\n\tLoadItemOptions,\n} from \"./item-loader.js\";\nexport {\n\tcreateFetchItemLoader,\n\tcreateLoadItem,\n\tItemLoadError,\n} from \"./item-loader.js\";\n\n// ============================================================================\n// Attempt Session\n// ============================================================================\n\nexport type {\n\tStorageLike,\n\tTestAttemptItemSession,\n\tTestAttemptSession,\n\tTestAttemptSessionNavigationState,\n\tTestAttemptSessionRealization,\n} from \"./attempt/TestSession.js\";\nexport {\n\tcreateMemoryStorage,\n\tcreateTestAttemptSessionIdentifier,\n\tcreateNewTestAttemptSession,\n\tgetBrowserLocalStorage,\n\tgetOrCreateAnonymousDeviceId,\n\tgetTestAttemptSessionStorageKey,\n\tloadTestAttemptSession,\n\tsaveTestAttemptSession,\n\tsetCurrentPosition,\n\tupsertItemSessionFromPieSessionChange,\n\tupsertVisitedItem,\n} from \"./attempt/TestSession.js\";\nexport type {\n\tAssessmentSession,\n\tAssessmentSectionSessionState,\n\tAssessmentSessionNavigationState,\n\tAssessmentSessionRealization,\n} from \"./attempt/AssessmentSession.js\";\nexport {\n\tcreateNewAssessmentSession,\n\tgetAssessmentSessionStorageKey,\n\tloadAssessmentSession,\n\tsaveAssessmentSession,\n\tsetCurrentSectionPosition,\n\tupsertSectionSession,\n} from \"./attempt/AssessmentSession.js\";\nexport type {\n\tActivitySessionPatchPayload,\n\tMapActivityToTestAttemptSessionArgs,\n\tPieBackendActivityDefinition,\n\tPieBackendActivityItemRef,\n\tPieBackendActivitySession,\n} from \"./attempt/adapters/activity-to-test-attempt-session.js\";\nexport {\n\tbuildActivitySessionItemUpdate,\n\tbuildActivitySessionPatchFromTestAttemptSession,\n\tmapActivityToTestAttemptSession,\n\ttoItemSessionsRecord,\n} from \"./attempt/adapters/activity-to-test-attempt-session.js\";\n\n// Section Player - Use @pie-players/pie-section-player web component\n\n// ============================================================================\n// Shared Components\n// ============================================================================\n\n// ItemToolBar custom element registration helper is exported via package.json exports field\n// Import using: import '@pie-players/pie-assessment-toolkit/components/item-toolbar-element';\n// PieAssessmentToolkit custom element registration helper is exported via package.json exports field\n"]}
@@ -101,8 +101,7 @@ export declare class ToolPolicyEngine {
101
101
  * re-runs caused by unrelated tracked reads): no-op patches do not
102
102
  * fire `onPolicyChange` listeners. This contract is relied on by
103
103
  * `PieAssessmentToolkit.svelte`'s prop-forwarding effect and by the
104
- * coordinator's `getFloatingTools()` / `decideToolPolicy()` lockstep
105
- * tests.
104
+ * coordinator's `decideToolPolicy()` tests.
106
105
  *
107
106
  * `pnpEnforcement` is stored on its own field and always emits with
108
107
  * a distinct `"pnp-enforcement"` reason when no other key changed,
@@ -103,8 +103,7 @@ export class ToolPolicyEngine {
103
103
  * re-runs caused by unrelated tracked reads): no-op patches do not
104
104
  * fire `onPolicyChange` listeners. This contract is relied on by
105
105
  * `PieAssessmentToolkit.svelte`'s prop-forwarding effect and by the
106
- * coordinator's `getFloatingTools()` / `decideToolPolicy()` lockstep
107
- * tests.
106
+ * coordinator's `decideToolPolicy()` tests.
108
107
  *
109
108
  * `pnpEnforcement` is stored on its own field and always emits with
110
109
  * a distinct `"pnp-enforcement"` reason when no other key changed,
@@ -1 +1 @@
1
- {"version":3,"file":"ToolPolicyEngine.js","sourceRoot":"","sources":["../../../src/policy/core/ToolPolicyEngine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAWH,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AAQjF,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,4BAA4B,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAoDhE,MAAM,aAAa,GAAyB,oBAAoB,CAAC;IAChE,MAAM,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;IACpC,SAA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AAC,CAAC;IAC/B,CAAC;IAEO,cAAc;QACrB,OAAO,MAAM,CAAC,MAAM,CAAC;YACpB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,cAAc,EAAE,IAAI,CAAC,cAAc;YACnC,cAAc,EAAE,IAAI,CAAC,cAAc;SACnC,CAAC,CAAC;IACJ,CAAC;IAEO,IAAI,CAAC,KAA4B;QACxC,KAAK,MAAM,QAAQ,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;YACnD,IAAI,CAAC;gBACJ,QAAQ,CAAC,KAAK,CAAC,CAAC;YACjB,CAAC;YAAC,MAAM,CAAC;gBACR,0DAA0D;gBAC1D,mDAAmD;YACpD,CAAC;QACF,CAAC;IACF,CAAC;IAEO,iBAAiB;QACxB,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;QACxD,CAAC;IACF,CAAC;CACD","sourcesContent":["/**\n * Tool Policy Engine — facade class (M8 — see\n * `.cursor/plans/m8-design.md` § 2).\n *\n * Wraps `composeDecision(...)` with engine-instance state:\n * - bound inputs (`tools`, `assessment`, `currentItemRef`, ...)\n * - registered custom `PolicySource`s\n * - `onPolicyChange` subscriber bus\n * - `dispose()` clean-up\n *\n * The class has no DOM dependency and no Svelte runes. It is safe to\n * instantiate inside a worker, in a Node test, or inside a CE\n * connectedCallback. The Svelte context glue (`TOOL_POLICY_ENGINE_KEY`)\n * lives in `engine-context.ts`.\n *\n * PR 1 ships the engine *without callers*. PR 2 wires it into\n * `ToolkitCoordinator`. PR 3 switches `<pie-item-toolbar>` over.\n */\n\nimport type {\n\tAssessmentEntity,\n\tAssessmentItemRef,\n} from \"@pie-players/pie-players-shared/types\";\n\nimport type {\n\tCanonicalToolsConfig,\n\tToolPlacementLevel,\n} from \"../../services/tools-config-normalizer.js\";\nimport { normalizeToolsConfig } from \"../../services/tools-config-normalizer.js\";\nimport type { ToolRegistry } from \"../../services/ToolRegistry.js\";\n\nimport type {\n\tToolPolicyDecision,\n\tToolPolicyDecisionRequest,\n} from \"./decision-types.js\";\nimport type { PolicySource } from \"./PolicySource.js\";\nimport { composeDecision } from \"./compose-decision.js\";\nimport { resolveDefaultPnpEnforcement } from \"./pnp-policy-inputs.js\";\nimport { PnpPolicySource } from \"../sources/PnpPolicySource.js\";\n\nexport type PnpEnforcementMode = \"on\" | \"off\";\n\nexport interface ToolPolicyEngineInputs {\n\ttools?: CanonicalToolsConfig | null;\n\tassessment?: AssessmentEntity | null;\n\tcurrentItemRef?: AssessmentItemRef | null;\n\t/**\n\t * Explicit PNP/profile override. When omitted (or `undefined`), the engine\n\t * defaults to {@link resolveDefaultPnpEnforcement} over the bound\n\t * `assessment` and `currentItemRef`: `\"on\"` if they carry any\n\t * PNP/profile policy material (PNP, district policy, test\n\t * administration, item-level required/restricted/parameters),\n\t * `\"off\"` otherwise. See `.cursor/plans/m8-design.md` F2.\n\t *\n\t * Hosts that want to force a mode pass `\"on\"` or `\"off\"`\n\t * explicitly. Embedded under `<pie-section-player-*>` the preferred\n\t * override flows through `runtime.tools.pnpEnforcement`.\n\t */\n\tpnpEnforcement?: PnpEnforcementMode;\n}\n\nexport interface ToolPolicyEngineArgs {\n\ttoolRegistry: ToolRegistry;\n\tinputs?: ToolPolicyEngineInputs;\n\tcustomSources?: readonly PolicySource[];\n\t/** Stable context label used in provenance trails. Defaults to \"tool-policy\". */\n\tcontextId?: string;\n}\n\nexport interface ToolPolicyChangeEvent {\n\t/** What changed in this update. */\n\treason:\n\t\t| \"inputs\"\n\t\t| \"policy-source-added\"\n\t\t| \"policy-source-removed\"\n\t\t| \"pnp-enforcement\"\n\t\t| \"disposed\";\n\t/** Snapshot of the engine's inputs after the change. */\n\tinputs: Readonly<ResolvedEngineInputs>;\n}\n\nexport interface ResolvedEngineInputs {\n\ttools: CanonicalToolsConfig;\n\tassessment: AssessmentEntity | null;\n\tcurrentItemRef: AssessmentItemRef | null;\n\tpnpEnforcement: PnpEnforcementMode;\n}\n\nexport type ToolPolicyChangeListener = (event: ToolPolicyChangeEvent) => void;\n\nconst DEFAULT_TOOLS: CanonicalToolsConfig = normalizeToolsConfig({\n\tpolicy: { allowed: [], blocked: [] },\n\tplacement: { section: [], item: [], passage: [] },\n\tproviders: {},\n});\n\nexport class ToolPolicyEngine {\n\tprivate readonly toolRegistry: ToolRegistry;\n\tprivate readonly contextId: string;\n\tprivate readonly pnpPolicySource: PnpPolicySource;\n\tprivate readonly customSources: PolicySource[];\n\tprivate readonly listeners = new Set<ToolPolicyChangeListener>();\n\n\tprivate tools: CanonicalToolsConfig;\n\tprivate assessment: AssessmentEntity | null;\n\tprivate currentItemRef: AssessmentItemRef | null;\n\tprivate pnpEnforcement: PnpEnforcementMode;\n\tprivate disposed = false;\n\n\tconstructor(args: ToolPolicyEngineArgs) {\n\t\tthis.toolRegistry = args.toolRegistry;\n\t\tthis.contextId = args.contextId ?? \"tool-policy\";\n\t\tthis.pnpPolicySource = new PnpPolicySource(this.toolRegistry);\n\t\tthis.customSources = args.customSources ? [...args.customSources] : [];\n\n\t\tconst inputs = args.inputs ?? {};\n\t\tthis.tools = inputs.tools ?? DEFAULT_TOOLS;\n\t\tthis.assessment = inputs.assessment ?? null;\n\t\tthis.currentItemRef = inputs.currentItemRef ?? null;\n\t\tthis.pnpEnforcement =\n\t\t\tinputs.pnpEnforcement ??\n\t\t\tresolveDefaultPnpEnforcement({\n\t\t\t\tassessment: this.assessment,\n\t\t\t\tcurrentItemRef: this.currentItemRef,\n\t\t\t});\n\t}\n\n\t/**\n\t * Resolve the visible tool set for a given placement level and\n\t * scope.\n\t *\n\t * `visibleTools` and `diagnostics` are deterministic with respect\n\t * to the engine's currently-bound inputs — calling `decide(...)`\n\t * twice with identical inputs returns structurally equal\n\t * `visibleTools` and `diagnostics`. The returned `provenance`\n\t * carries call-time `evaluatedAt` timestamps generated by\n\t * `ToolPolicyProvenanceBuilder` (one per `decide(...)`); two\n\t * back-to-back calls therefore produce different `evaluatedAt`\n\t * values even though the policy decision itself is identical.\n\t * Hosts that want timestamp-stable provenance should reuse a\n\t * cached `ToolPolicyDecision` rather than re-call `decide(...)`.\n\t */\n\tdecide(request: ToolPolicyDecisionRequest): ToolPolicyDecision {\n\t\tthis.assertNotDisposed();\n\t\tconst requestContextId = request.scope.scopeId\n\t\t\t? `${this.contextId}:${request.level}:${request.scope.scopeId}`\n\t\t\t: `${this.contextId}:${request.level}`;\n\t\treturn composeDecision({\n\t\t\trequest,\n\t\t\ttools: this.tools,\n\t\t\tpnpPolicy: {\n\t\t\t\tsource: this.pnpPolicySource,\n\t\t\t\tassessment: this.assessment ?? undefined,\n\t\t\t\tcurrentItemRef: this.currentItemRef ?? undefined,\n\t\t\t\tenforcement: this.pnpEnforcement,\n\t\t\t},\n\t\t\tcustomSources: this.customSources,\n\t\t\tcontextId: requestContextId,\n\t\t});\n\t}\n\n\t/**\n\t * Convenience wrapper for hosts that just want the visible tool\n\t * IDs. Equivalent to `decide(...).visibleTools.map(e => e.toolId)`.\n\t */\n\tgetVisibleToolIds(level: ToolPlacementLevel, scopeId: string): string[] {\n\t\treturn this.decide({\n\t\t\tlevel,\n\t\t\tscope: { level, scopeId },\n\t\t}).visibleTools.map((entry) => entry.toolId);\n\t}\n\n\t/**\n\t * Apply a partial input update.\n\t *\n\t * Each key is value-diffed via `Object.is` before storing, so callers\n\t * may safely re-push the same reference (e.g. on Svelte effect\n\t * re-runs caused by unrelated tracked reads): no-op patches do not\n\t * fire `onPolicyChange` listeners. This contract is relied on by\n\t * `PieAssessmentToolkit.svelte`'s prop-forwarding effect and by the\n\t * coordinator's `getFloatingTools()` / `decideToolPolicy()` lockstep\n\t * tests.\n\t *\n\t * `pnpEnforcement` is stored on its own field and always emits with\n\t * a distinct `\"pnp-enforcement\"` reason when no other key changed,\n\t * so PR 4's auto-on flip can target that reason without a separate\n\t * event channel.\n\t */\n\tupdateInputs(patch: Partial<ToolPolicyEngineInputs>): void {\n\t\tthis.assertNotDisposed();\n\t\tlet changed = false;\n\t\tlet pnpChanged = false;\n\t\tif (\"tools\" in patch) {\n\t\t\tconst next = patch.tools ?? DEFAULT_TOOLS;\n\t\t\tif (!Object.is(this.tools, next)) {\n\t\t\t\tthis.tools = next;\n\t\t\t\tchanged = true;\n\t\t\t}\n\t\t}\n\t\tif (\"assessment\" in patch) {\n\t\t\tconst next = patch.assessment ?? null;\n\t\t\tif (!Object.is(this.assessment, next)) {\n\t\t\t\tthis.assessment = next;\n\t\t\t\tchanged = true;\n\t\t\t}\n\t\t}\n\t\tif (\"currentItemRef\" in patch) {\n\t\t\tconst next = patch.currentItemRef ?? null;\n\t\t\tif (!Object.is(this.currentItemRef, next)) {\n\t\t\t\tthis.currentItemRef = next;\n\t\t\t\tchanged = true;\n\t\t\t}\n\t\t}\n\t\tif (\"pnpEnforcement\" in patch && patch.pnpEnforcement) {\n\t\t\tif (this.pnpEnforcement !== patch.pnpEnforcement) {\n\t\t\t\tthis.pnpEnforcement = patch.pnpEnforcement;\n\t\t\t\tpnpChanged = true;\n\t\t\t}\n\t\t}\n\t\tif (changed || pnpChanged) {\n\t\t\tthis.emit({\n\t\t\t\treason: pnpChanged && !changed ? \"pnp-enforcement\" : \"inputs\",\n\t\t\t\tinputs: this.snapshotInputs(),\n\t\t\t});\n\t\t}\n\t}\n\n\tregisterPolicySource(source: PolicySource): () => void {\n\t\tthis.assertNotDisposed();\n\t\tthis.customSources.push(source);\n\t\tthis.emit({\n\t\t\treason: \"policy-source-added\",\n\t\t\tinputs: this.snapshotInputs(),\n\t\t});\n\t\treturn () => {\n\t\t\tconst idx = this.customSources.indexOf(source);\n\t\t\tif (idx !== -1) {\n\t\t\t\tthis.customSources.splice(idx, 1);\n\t\t\t\tif (!this.disposed) {\n\t\t\t\t\tthis.emit({\n\t\t\t\t\t\treason: \"policy-source-removed\",\n\t\t\t\t\t\tinputs: this.snapshotInputs(),\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t}\n\n\tonPolicyChange(listener: ToolPolicyChangeListener): () => void {\n\t\tthis.listeners.add(listener);\n\t\treturn () => {\n\t\t\tthis.listeners.delete(listener);\n\t\t};\n\t}\n\n\tgetInputs(): Readonly<ResolvedEngineInputs> {\n\t\treturn this.snapshotInputs();\n\t}\n\n\tdispose(): void {\n\t\tif (this.disposed) return;\n\t\tthis.disposed = true;\n\t\tthis.emit({\n\t\t\treason: \"disposed\",\n\t\t\tinputs: this.snapshotInputs(),\n\t\t});\n\t\tthis.listeners.clear();\n\t\tthis.customSources.length = 0;\n\t}\n\n\tprivate snapshotInputs(): Readonly<ResolvedEngineInputs> {\n\t\treturn Object.freeze({\n\t\t\ttools: this.tools,\n\t\t\tassessment: this.assessment,\n\t\t\tcurrentItemRef: this.currentItemRef,\n\t\t\tpnpEnforcement: this.pnpEnforcement,\n\t\t});\n\t}\n\n\tprivate emit(event: ToolPolicyChangeEvent): void {\n\t\tfor (const listener of Array.from(this.listeners)) {\n\t\t\ttry {\n\t\t\t\tlistener(event);\n\t\t\t} catch {\n\t\t\t\t// Subscriber errors must not break the engine. Hosts that\n\t\t\t\t// want error telemetry should wrap their listener.\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate assertNotDisposed(): void {\n\t\tif (this.disposed) {\n\t\t\tthrow new Error(\"ToolPolicyEngine has been disposed.\");\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"ToolPolicyEngine.js","sourceRoot":"","sources":["../../../src/policy/core/ToolPolicyEngine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAWH,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AAQjF,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,4BAA4B,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;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,cAAc,EAAE;SAC7B,CAAC,CAAC;QACH,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;QACvB,IAAI,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC;IAC/B,CAAC;IAEO,cAAc;QACrB,OAAO,MAAM,CAAC,MAAM,CAAC;YACpB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,cAAc,EAAE,IAAI,CAAC,cAAc;YACnC,cAAc,EAAE,IAAI,CAAC,cAAc;SACnC,CAAC,CAAC;IACJ,CAAC;IAEO,IAAI,CAAC,KAA4B;QACxC,KAAK,MAAM,QAAQ,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;YACnD,IAAI,CAAC;gBACJ,QAAQ,CAAC,KAAK,CAAC,CAAC;YACjB,CAAC;YAAC,MAAM,CAAC;gBACR,0DAA0D;gBAC1D,mDAAmD;YACpD,CAAC;QACF,CAAC;IACF,CAAC;IAEO,iBAAiB;QACxB,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;QACxD,CAAC;IACF,CAAC;CACD","sourcesContent":["/**\n * Tool Policy Engine — facade class (M8 — see\n * `.cursor/plans/m8-design.md` § 2).\n *\n * Wraps `composeDecision(...)` with engine-instance state:\n * - bound inputs (`tools`, `assessment`, `currentItemRef`, ...)\n * - registered custom `PolicySource`s\n * - `onPolicyChange` subscriber bus\n * - `dispose()` clean-up\n *\n * The class has no DOM dependency and no Svelte runes. It is safe to\n * instantiate inside a worker, in a Node test, or inside a CE\n * connectedCallback. The Svelte context glue (`TOOL_POLICY_ENGINE_KEY`)\n * lives in `engine-context.ts`.\n *\n * PR 1 ships the engine *without callers*. PR 2 wires it into\n * `ToolkitCoordinator`. PR 3 switches `<pie-item-toolbar>` over.\n */\n\nimport type {\n\tAssessmentEntity,\n\tAssessmentItemRef,\n} from \"@pie-players/pie-players-shared/types\";\n\nimport type {\n\tCanonicalToolsConfig,\n\tToolPlacementLevel,\n} from \"../../services/tools-config-normalizer.js\";\nimport { normalizeToolsConfig } from \"../../services/tools-config-normalizer.js\";\nimport type { ToolRegistry } from \"../../services/ToolRegistry.js\";\n\nimport type {\n\tToolPolicyDecision,\n\tToolPolicyDecisionRequest,\n} from \"./decision-types.js\";\nimport type { PolicySource } from \"./PolicySource.js\";\nimport { composeDecision } from \"./compose-decision.js\";\nimport { resolveDefaultPnpEnforcement } from \"./pnp-policy-inputs.js\";\nimport { PnpPolicySource } from \"../sources/PnpPolicySource.js\";\n\nexport type PnpEnforcementMode = \"on\" | \"off\";\n\nexport interface ToolPolicyEngineInputs {\n\ttools?: CanonicalToolsConfig | null;\n\tassessment?: AssessmentEntity | null;\n\tcurrentItemRef?: AssessmentItemRef | null;\n\t/**\n\t * Explicit PNP/profile override. When omitted (or `undefined`), the engine\n\t * defaults to {@link resolveDefaultPnpEnforcement} over the bound\n\t * `assessment` and `currentItemRef`: `\"on\"` if they carry any\n\t * PNP/profile policy material (PNP, district policy, test\n\t * administration, item-level required/restricted/parameters),\n\t * `\"off\"` otherwise. See `.cursor/plans/m8-design.md` F2.\n\t *\n\t * Hosts that want to force a mode pass `\"on\"` or `\"off\"`\n\t * explicitly. Embedded under `<pie-section-player-*>` the preferred\n\t * override flows through `runtime.tools.pnpEnforcement`.\n\t */\n\tpnpEnforcement?: PnpEnforcementMode;\n}\n\nexport interface ToolPolicyEngineArgs {\n\ttoolRegistry: ToolRegistry;\n\tinputs?: ToolPolicyEngineInputs;\n\tcustomSources?: readonly PolicySource[];\n\t/** Stable context label used in provenance trails. Defaults to \"tool-policy\". */\n\tcontextId?: string;\n}\n\nexport interface ToolPolicyChangeEvent {\n\t/** What changed in this update. */\n\treason:\n\t\t| \"inputs\"\n\t\t| \"policy-source-added\"\n\t\t| \"policy-source-removed\"\n\t\t| \"pnp-enforcement\"\n\t\t| \"disposed\";\n\t/** Snapshot of the engine's inputs after the change. */\n\tinputs: Readonly<ResolvedEngineInputs>;\n}\n\nexport interface ResolvedEngineInputs {\n\ttools: CanonicalToolsConfig;\n\tassessment: AssessmentEntity | null;\n\tcurrentItemRef: AssessmentItemRef | null;\n\tpnpEnforcement: PnpEnforcementMode;\n}\n\nexport type ToolPolicyChangeListener = (event: ToolPolicyChangeEvent) => void;\n\nconst DEFAULT_TOOLS: CanonicalToolsConfig = normalizeToolsConfig({\n\tpolicy: { allowed: [], blocked: [] },\n\tplacement: { section: [], item: [], passage: [] },\n\tproviders: {},\n});\n\nexport class ToolPolicyEngine {\n\tprivate readonly toolRegistry: ToolRegistry;\n\tprivate readonly contextId: string;\n\tprivate readonly pnpPolicySource: PnpPolicySource;\n\tprivate readonly customSources: PolicySource[];\n\tprivate readonly listeners = new Set<ToolPolicyChangeListener>();\n\n\tprivate tools: CanonicalToolsConfig;\n\tprivate assessment: AssessmentEntity | null;\n\tprivate currentItemRef: AssessmentItemRef | null;\n\tprivate pnpEnforcement: PnpEnforcementMode;\n\tprivate disposed = false;\n\n\tconstructor(args: ToolPolicyEngineArgs) {\n\t\tthis.toolRegistry = args.toolRegistry;\n\t\tthis.contextId = args.contextId ?? \"tool-policy\";\n\t\tthis.pnpPolicySource = new PnpPolicySource(this.toolRegistry);\n\t\tthis.customSources = args.customSources ? [...args.customSources] : [];\n\n\t\tconst inputs = args.inputs ?? {};\n\t\tthis.tools = inputs.tools ?? DEFAULT_TOOLS;\n\t\tthis.assessment = inputs.assessment ?? null;\n\t\tthis.currentItemRef = inputs.currentItemRef ?? null;\n\t\tthis.pnpEnforcement =\n\t\t\tinputs.pnpEnforcement ??\n\t\t\tresolveDefaultPnpEnforcement({\n\t\t\t\tassessment: this.assessment,\n\t\t\t\tcurrentItemRef: this.currentItemRef,\n\t\t\t});\n\t}\n\n\t/**\n\t * Resolve the visible tool set for a given placement level and\n\t * scope.\n\t *\n\t * `visibleTools` and `diagnostics` are deterministic with respect\n\t * to the engine's currently-bound inputs — calling `decide(...)`\n\t * twice with identical inputs returns structurally equal\n\t * `visibleTools` and `diagnostics`. The returned `provenance`\n\t * carries call-time `evaluatedAt` timestamps generated by\n\t * `ToolPolicyProvenanceBuilder` (one per `decide(...)`); two\n\t * back-to-back calls therefore produce different `evaluatedAt`\n\t * values even though the policy decision itself is identical.\n\t * Hosts that want timestamp-stable provenance should reuse a\n\t * cached `ToolPolicyDecision` rather than re-call `decide(...)`.\n\t */\n\tdecide(request: ToolPolicyDecisionRequest): ToolPolicyDecision {\n\t\tthis.assertNotDisposed();\n\t\tconst requestContextId = request.scope.scopeId\n\t\t\t? `${this.contextId}:${request.level}:${request.scope.scopeId}`\n\t\t\t: `${this.contextId}:${request.level}`;\n\t\treturn composeDecision({\n\t\t\trequest,\n\t\t\ttools: this.tools,\n\t\t\tpnpPolicy: {\n\t\t\t\tsource: this.pnpPolicySource,\n\t\t\t\tassessment: this.assessment ?? undefined,\n\t\t\t\tcurrentItemRef: this.currentItemRef ?? undefined,\n\t\t\t\tenforcement: this.pnpEnforcement,\n\t\t\t},\n\t\t\tcustomSources: this.customSources,\n\t\t\tcontextId: requestContextId,\n\t\t});\n\t}\n\n\t/**\n\t * Convenience wrapper for hosts that just want the visible tool\n\t * IDs. Equivalent to `decide(...).visibleTools.map(e => e.toolId)`.\n\t */\n\tgetVisibleToolIds(level: ToolPlacementLevel, scopeId: string): string[] {\n\t\treturn this.decide({\n\t\t\tlevel,\n\t\t\tscope: { level, scopeId },\n\t\t}).visibleTools.map((entry) => entry.toolId);\n\t}\n\n\t/**\n\t * Apply a partial input update.\n\t *\n\t * Each key is value-diffed via `Object.is` before storing, so callers\n\t * may safely re-push the same reference (e.g. on Svelte effect\n\t * re-runs caused by unrelated tracked reads): no-op patches do not\n\t * fire `onPolicyChange` listeners. This contract is relied on by\n\t * `PieAssessmentToolkit.svelte`'s prop-forwarding effect and by the\n\t * coordinator's `decideToolPolicy()` tests.\n\t *\n\t * `pnpEnforcement` is stored on its own field and always emits with\n\t * a distinct `\"pnp-enforcement\"` reason when no other key changed,\n\t * so PR 4's auto-on flip can target that reason without a separate\n\t * event channel.\n\t */\n\tupdateInputs(patch: Partial<ToolPolicyEngineInputs>): void {\n\t\tthis.assertNotDisposed();\n\t\tlet changed = false;\n\t\tlet pnpChanged = false;\n\t\tif (\"tools\" in patch) {\n\t\t\tconst next = patch.tools ?? DEFAULT_TOOLS;\n\t\t\tif (!Object.is(this.tools, next)) {\n\t\t\t\tthis.tools = next;\n\t\t\t\tchanged = true;\n\t\t\t}\n\t\t}\n\t\tif (\"assessment\" in patch) {\n\t\t\tconst next = patch.assessment ?? null;\n\t\t\tif (!Object.is(this.assessment, next)) {\n\t\t\t\tthis.assessment = next;\n\t\t\t\tchanged = true;\n\t\t\t}\n\t\t}\n\t\tif (\"currentItemRef\" in patch) {\n\t\t\tconst next = patch.currentItemRef ?? null;\n\t\t\tif (!Object.is(this.currentItemRef, next)) {\n\t\t\t\tthis.currentItemRef = next;\n\t\t\t\tchanged = true;\n\t\t\t}\n\t\t}\n\t\tif (\"pnpEnforcement\" in patch && patch.pnpEnforcement) {\n\t\t\tif (this.pnpEnforcement !== patch.pnpEnforcement) {\n\t\t\t\tthis.pnpEnforcement = patch.pnpEnforcement;\n\t\t\t\tpnpChanged = true;\n\t\t\t}\n\t\t}\n\t\tif (changed || pnpChanged) {\n\t\t\tthis.emit({\n\t\t\t\treason: pnpChanged && !changed ? \"pnp-enforcement\" : \"inputs\",\n\t\t\t\tinputs: this.snapshotInputs(),\n\t\t\t});\n\t\t}\n\t}\n\n\tregisterPolicySource(source: PolicySource): () => void {\n\t\tthis.assertNotDisposed();\n\t\tthis.customSources.push(source);\n\t\tthis.emit({\n\t\t\treason: \"policy-source-added\",\n\t\t\tinputs: this.snapshotInputs(),\n\t\t});\n\t\treturn () => {\n\t\t\tconst idx = this.customSources.indexOf(source);\n\t\t\tif (idx !== -1) {\n\t\t\t\tthis.customSources.splice(idx, 1);\n\t\t\t\tif (!this.disposed) {\n\t\t\t\t\tthis.emit({\n\t\t\t\t\t\treason: \"policy-source-removed\",\n\t\t\t\t\t\tinputs: this.snapshotInputs(),\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t}\n\n\tonPolicyChange(listener: ToolPolicyChangeListener): () => void {\n\t\tthis.listeners.add(listener);\n\t\treturn () => {\n\t\t\tthis.listeners.delete(listener);\n\t\t};\n\t}\n\n\tgetInputs(): Readonly<ResolvedEngineInputs> {\n\t\treturn this.snapshotInputs();\n\t}\n\n\tdispose(): void {\n\t\tif (this.disposed) return;\n\t\tthis.disposed = true;\n\t\tthis.emit({\n\t\t\treason: \"disposed\",\n\t\t\tinputs: this.snapshotInputs(),\n\t\t});\n\t\tthis.listeners.clear();\n\t\tthis.customSources.length = 0;\n\t}\n\n\tprivate snapshotInputs(): Readonly<ResolvedEngineInputs> {\n\t\treturn Object.freeze({\n\t\t\ttools: this.tools,\n\t\t\tassessment: this.assessment,\n\t\t\tcurrentItemRef: this.currentItemRef,\n\t\t\tpnpEnforcement: this.pnpEnforcement,\n\t\t});\n\t}\n\n\tprivate emit(event: ToolPolicyChangeEvent): void {\n\t\tfor (const listener of Array.from(this.listeners)) {\n\t\t\ttry {\n\t\t\t\tlistener(event);\n\t\t\t} catch {\n\t\t\t\t// Subscriber errors must not break the engine. Hosts that\n\t\t\t\t// want error telemetry should wrap their listener.\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate assertNotDisposed(): void {\n\t\tif (this.disposed) {\n\t\t\tthrow new Error(\"ToolPolicyEngine has been disposed.\");\n\t\t}\n\t}\n}\n"]}
@@ -14,9 +14,8 @@
14
14
  * carries profile policy material."
15
15
  *
16
16
  * The rule is intentionally narrow. Hosts that bind a bare assessment
17
- * record (only `id` / `name`, no PNP and no settings) get the legacy
18
- * floating-tools behavior — PNP/profile gates do not engage. The flip happens
19
- * the moment the assessment carries any of:
17
+ * record (only `id` / `name`, no PNP and no settings) do not engage
18
+ * PNP/profile gates. The flip happens the moment the assessment carries any of:
20
19
  *
21
20
  * - `personalNeedsProfile` (any `supports`, `prohibitedSupports`, or
22
21
  * `activateAtInit`),
@@ -14,9 +14,8 @@
14
14
  * carries profile policy material."
15
15
  *
16
16
  * The rule is intentionally narrow. Hosts that bind a bare assessment
17
- * record (only `id` / `name`, no PNP and no settings) get the legacy
18
- * floating-tools behavior — PNP/profile gates do not engage. The flip happens
19
- * the moment the assessment carries any of:
17
+ * record (only `id` / `name`, no PNP and no settings) do not engage
18
+ * PNP/profile gates. The flip happens the moment the assessment carries any of:
20
19
  *
21
20
  * - `personalNeedsProfile` (any `supports`, `prohibitedSupports`, or
22
21
  * `activateAtInit`),
@@ -1 +1 @@
1
- {"version":3,"file":"pnp-policy-inputs.js","sourceRoot":"","sources":["../../../src/policy/core/pnp-policy-inputs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAOH;;;;;;;GAOG;AACH,MAAM,UAAU,4BAA4B,CAC3C,UAA+C;IAE/C,IAAI,CAAC,UAAU;QAAE,OAAO,KAAK,CAAC;IAC9B,MAAM,GAAG,GAAG,UAAU,CAAC,oBAAoB,CAAC;IAC5C,IAAI,GAAG,EAAE,CAAC;QACT,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC;YAAE,OAAO,IAAI,CAAC;QACxE,IACC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC;YACrC,GAAG,CAAC,kBAAkB,CAAC,MAAM,GAAG,CAAC,EAChC,CAAC;YACF,OAAO,IAAI,CAAC;QACb,CAAC;QACD,IACC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC;YACjC,GAAG,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC,EAC5B,CAAC;YACF,OAAO,IAAI,CAAC;QACb,CAAC;IACF,CAAC;IACD,MAAM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C,MAAM,KAAK,CAAC,EACzD,CAAC;oBACF,SAAS;gBACV,CAAC;gBACD,OAAO,IAAI,CAAC;YACb,CAAC;QACF,CAAC;IACF,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,yBAAyB,CACxC,OAA6C;IAE7C,MAAM,QAAQ,GAAG,OAAO,EAAE,QAAQ,CAAC;IACnC,IAAI,CAAC,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC5B,IACC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAC;QACrC,QAAQ,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,EAChC,CAAC;QACF,OAAO,IAAI,CAAC;IACb,CAAC;IACD,IACC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAC;QACvC,QAAQ,CAAC,eAAe,CAAC,MAAM,GAAG,CAAC,EAClC,CAAC;QACF,OAAO,IAAI,CAAC;IACb,CAAC;IACD,IACC,QAAQ,CAAC,cAAc;QACvB,OAAO,QAAQ,CAAC,cAAc,KAAK,QAAQ;QAC3C,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC,MAAM,GAAG,CAAC,EAC9C,CAAC;QACF,OAAO,IAAI,CAAC;IACb,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,4BAA4B,CAAC,IAG5C;IACA,IAAI,4BAA4B,CAAC,IAAI,CAAC,UAAU,CAAC;QAAE,OAAO,IAAI,CAAC;IAC/D,IAAI,yBAAyB,CAAC,IAAI,CAAC,cAAc,CAAC;QAAE,OAAO,IAAI,CAAC;IAChE,OAAO,KAAK,CAAC;AACd,CAAC","sourcesContent":["/**\n * PNP/profile policy input detection (M8 PR 4 — see `.cursor/plans/m8-design.md` F2 and\n * `.cursor/plans/m8-implementation-plan.md` § PR 4).\n *\n * Pure helpers that decide whether the inputs the engine has been given\n * actually carry PNP/profile policy material. Used by:\n *\n * - {@link ToolPolicyEngine}'s constructor as the auto-default for\n * `pnpEnforcement` when the host did not pass an explicit `\"on\"` /\n * `\"off\"`.\n * - {@link ToolkitCoordinator.resolveEffectivePnpEnforcement} as the\n * auto-mode rule. PR 2 used a coarse \"any non-null assessment → on\"\n * placeholder; PR 4 narrows it to \"assessment OR currentItemRef\n * carries profile policy material.\"\n *\n * The rule is intentionally narrow. Hosts that bind a bare assessment\n * record (only `id` / `name`, no PNP and no settings) get the legacy\n * floating-tools behavior — PNP/profile gates do not engage. The flip happens\n * the moment the assessment carries any of:\n *\n * - `personalNeedsProfile` (any `supports`, `prohibitedSupports`, or\n * `activateAtInit`),\n * - `settings.districtPolicy` (any `blockedTools`, `requiredTools`,\n * or `policies`),\n * - `settings.testAdministration` (any populated key — `mode`,\n * `toolOverrides`, etc.),\n * - or the bound `currentItemRef.settings` carries\n * `requiredTools` / `restrictedTools` / `toolParameters`.\n *\n * Hosts opt out of the auto-on behavior by passing\n * `pnpEnforcement: \"off\"` explicitly (engine input or\n * `ToolkitCoordinator.setPnpEnforcement(\"off\")`).\n */\n\nimport type {\n\tAssessmentEntity,\n\tAssessmentItemRef,\n} from \"@pie-players/pie-players-shared/types\";\n\n/**\n * Return `true` when the assessment carries any PNP/profile policy\n * material that the engine's `PnpPolicySource` would consume.\n *\n * The check is structural — the presence of a non-empty PNP, district\n * policy, or test administration block is enough; the content does not\n * have to validate against any specific rule.\n */\nexport function assessmentHasPnpPolicyInputs(\n\tassessment: AssessmentEntity | null | undefined,\n): boolean {\n\tif (!assessment) return false;\n\tconst pnp = assessment.personalNeedsProfile;\n\tif (pnp) {\n\t\tif (Array.isArray(pnp.supports) && pnp.supports.length > 0) return true;\n\t\tif (\n\t\t\tArray.isArray(pnp.prohibitedSupports) &&\n\t\t\tpnp.prohibitedSupports.length > 0\n\t\t) {\n\t\t\treturn true;\n\t\t}\n\t\tif (\n\t\t\tArray.isArray(pnp.activateAtInit) &&\n\t\t\tpnp.activateAtInit.length > 0\n\t\t) {\n\t\t\treturn true;\n\t\t}\n\t}\n\tconst settings = assessment.settings;\n\tif (settings) {\n\t\tconst district = settings.districtPolicy;\n\t\tif (district) {\n\t\t\tif (\n\t\t\t\tArray.isArray(district.blockedTools) &&\n\t\t\t\tdistrict.blockedTools.length > 0\n\t\t\t) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif (\n\t\t\t\tArray.isArray(district.requiredTools) &&\n\t\t\t\tdistrict.requiredTools.length > 0\n\t\t\t) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif (\n\t\t\t\tdistrict.policies &&\n\t\t\t\ttypeof district.policies === \"object\" &&\n\t\t\t\tObject.keys(district.policies).length > 0\n\t\t\t) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\tconst admin = settings.testAdministration;\n\t\tif (admin && typeof admin === \"object\") {\n\t\t\tfor (const key of Object.keys(admin)) {\n\t\t\t\tconst value = (admin as Record<string, unknown>)[key];\n\t\t\t\tif (value === undefined || value === null) continue;\n\t\t\t\tif (Array.isArray(value) && value.length === 0) continue;\n\t\t\t\tif (\n\t\t\t\t\ttypeof value === \"object\" &&\n\t\t\t\t\t!Array.isArray(value) &&\n\t\t\t\t\tObject.keys(value as Record<string, unknown>).length === 0\n\t\t\t\t) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t}\n\treturn false;\n}\n\n/**\n * Return `true` when the bound item reference carries item-level profile policy\n * material (`requiredTools`, `restrictedTools`, or `toolParameters`).\n *\n * Used in addition to {@link assessmentHasPnpPolicyInputs} so a host that\n * navigates to an item with profile-relevant settings — without a parent\n * assessment carrying its own PNP/district/test-admin block — still\n * gets PNP/profile gates engaged for that item.\n */\nexport function itemRefHasPnpPolicyInputs(\n\titemRef: AssessmentItemRef | null | undefined,\n): boolean {\n\tconst settings = itemRef?.settings;\n\tif (!settings) return false;\n\tif (\n\t\tArray.isArray(settings.requiredTools) &&\n\t\tsettings.requiredTools.length > 0\n\t) {\n\t\treturn true;\n\t}\n\tif (\n\t\tArray.isArray(settings.restrictedTools) &&\n\t\tsettings.restrictedTools.length > 0\n\t) {\n\t\treturn true;\n\t}\n\tif (\n\t\tsettings.toolParameters &&\n\t\ttypeof settings.toolParameters === \"object\" &&\n\t\tObject.keys(settings.toolParameters).length > 0\n\t) {\n\t\treturn true;\n\t}\n\treturn false;\n}\n\n/**\n * Resolve the default `pnpEnforcement` mode given the bound inputs.\n *\n * Returns `\"on\"` when {@link assessmentHasPnpPolicyInputs} or\n * {@link itemRefHasPnpPolicyInputs} reports any profile policy material; otherwise\n * `\"off\"`. Hosts override the default by passing an explicit\n * `pnpEnforcement` value (engine input) or by calling\n * `ToolkitCoordinator.setPnpEnforcement(\"on\" | \"off\")`.\n */\nexport function resolveDefaultPnpEnforcement(args: {\n\tassessment?: AssessmentEntity | null;\n\tcurrentItemRef?: AssessmentItemRef | null;\n}): \"on\" | \"off\" {\n\tif (assessmentHasPnpPolicyInputs(args.assessment)) return \"on\";\n\tif (itemRefHasPnpPolicyInputs(args.currentItemRef)) return \"on\";\n\treturn \"off\";\n}\n"]}
1
+ {"version":3,"file":"pnp-policy-inputs.js","sourceRoot":"","sources":["../../../src/policy/core/pnp-policy-inputs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAOH;;;;;;;GAOG;AACH,MAAM,UAAU,4BAA4B,CAC3C,UAA+C;IAE/C,IAAI,CAAC,UAAU;QAAE,OAAO,KAAK,CAAC;IAC9B,MAAM,GAAG,GAAG,UAAU,CAAC,oBAAoB,CAAC;IAC5C,IAAI,GAAG,EAAE,CAAC;QACT,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC;YAAE,OAAO,IAAI,CAAC;QACxE,IACC,KAAK,CAAC,OAAO,CAAC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AAI,CAAC,UAAU,CAAC;QAAE,OAAO,IAAI,CAAC;IAC/D,IAAI,yBAAyB,CAAC,IAAI,CAAC,cAAc,CAAC;QAAE,OAAO,IAAI,CAAC;IAChE,OAAO,KAAK,CAAC;AACd,CAAC","sourcesContent":["/**\n * PNP/profile policy input detection (M8 PR 4 — see `.cursor/plans/m8-design.md` F2 and\n * `.cursor/plans/m8-implementation-plan.md` § PR 4).\n *\n * Pure helpers that decide whether the inputs the engine has been given\n * actually carry PNP/profile policy material. Used by:\n *\n * - {@link ToolPolicyEngine}'s constructor as the auto-default for\n * `pnpEnforcement` when the host did not pass an explicit `\"on\"` /\n * `\"off\"`.\n * - {@link ToolkitCoordinator.resolveEffectivePnpEnforcement} as the\n * auto-mode rule. PR 2 used a coarse \"any non-null assessment → on\"\n * placeholder; PR 4 narrows it to \"assessment OR currentItemRef\n * carries profile policy material.\"\n *\n * The rule is intentionally narrow. Hosts that bind a bare assessment\n * record (only `id` / `name`, no PNP and no settings) do not engage\n * PNP/profile gates. The flip happens the moment the assessment carries any of:\n *\n * - `personalNeedsProfile` (any `supports`, `prohibitedSupports`, or\n * `activateAtInit`),\n * - `settings.districtPolicy` (any `blockedTools`, `requiredTools`,\n * or `policies`),\n * - `settings.testAdministration` (any populated key — `mode`,\n * `toolOverrides`, etc.),\n * - or the bound `currentItemRef.settings` carries\n * `requiredTools` / `restrictedTools` / `toolParameters`.\n *\n * Hosts opt out of the auto-on behavior by passing\n * `pnpEnforcement: \"off\"` explicitly (engine input or\n * `ToolkitCoordinator.setPnpEnforcement(\"off\")`).\n */\n\nimport type {\n\tAssessmentEntity,\n\tAssessmentItemRef,\n} from \"@pie-players/pie-players-shared/types\";\n\n/**\n * Return `true` when the assessment carries any PNP/profile policy\n * material that the engine's `PnpPolicySource` would consume.\n *\n * The check is structural — the presence of a non-empty PNP, district\n * policy, or test administration block is enough; the content does not\n * have to validate against any specific rule.\n */\nexport function assessmentHasPnpPolicyInputs(\n\tassessment: AssessmentEntity | null | undefined,\n): boolean {\n\tif (!assessment) return false;\n\tconst pnp = assessment.personalNeedsProfile;\n\tif (pnp) {\n\t\tif (Array.isArray(pnp.supports) && pnp.supports.length > 0) return true;\n\t\tif (\n\t\t\tArray.isArray(pnp.prohibitedSupports) &&\n\t\t\tpnp.prohibitedSupports.length > 0\n\t\t) {\n\t\t\treturn true;\n\t\t}\n\t\tif (\n\t\t\tArray.isArray(pnp.activateAtInit) &&\n\t\t\tpnp.activateAtInit.length > 0\n\t\t) {\n\t\t\treturn true;\n\t\t}\n\t}\n\tconst settings = assessment.settings;\n\tif (settings) {\n\t\tconst district = settings.districtPolicy;\n\t\tif (district) {\n\t\t\tif (\n\t\t\t\tArray.isArray(district.blockedTools) &&\n\t\t\t\tdistrict.blockedTools.length > 0\n\t\t\t) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif (\n\t\t\t\tArray.isArray(district.requiredTools) &&\n\t\t\t\tdistrict.requiredTools.length > 0\n\t\t\t) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif (\n\t\t\t\tdistrict.policies &&\n\t\t\t\ttypeof district.policies === \"object\" &&\n\t\t\t\tObject.keys(district.policies).length > 0\n\t\t\t) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\tconst admin = settings.testAdministration;\n\t\tif (admin && typeof admin === \"object\") {\n\t\t\tfor (const key of Object.keys(admin)) {\n\t\t\t\tconst value = (admin as Record<string, unknown>)[key];\n\t\t\t\tif (value === undefined || value === null) continue;\n\t\t\t\tif (Array.isArray(value) && value.length === 0) continue;\n\t\t\t\tif (\n\t\t\t\t\ttypeof value === \"object\" &&\n\t\t\t\t\t!Array.isArray(value) &&\n\t\t\t\t\tObject.keys(value as Record<string, unknown>).length === 0\n\t\t\t\t) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t}\n\treturn false;\n}\n\n/**\n * Return `true` when the bound item reference carries item-level profile policy\n * material (`requiredTools`, `restrictedTools`, or `toolParameters`).\n *\n * Used in addition to {@link assessmentHasPnpPolicyInputs} so a host that\n * navigates to an item with profile-relevant settings — without a parent\n * assessment carrying its own PNP/district/test-admin block — still\n * gets PNP/profile gates engaged for that item.\n */\nexport function itemRefHasPnpPolicyInputs(\n\titemRef: AssessmentItemRef | null | undefined,\n): boolean {\n\tconst settings = itemRef?.settings;\n\tif (!settings) return false;\n\tif (\n\t\tArray.isArray(settings.requiredTools) &&\n\t\tsettings.requiredTools.length > 0\n\t) {\n\t\treturn true;\n\t}\n\tif (\n\t\tArray.isArray(settings.restrictedTools) &&\n\t\tsettings.restrictedTools.length > 0\n\t) {\n\t\treturn true;\n\t}\n\tif (\n\t\tsettings.toolParameters &&\n\t\ttypeof settings.toolParameters === \"object\" &&\n\t\tObject.keys(settings.toolParameters).length > 0\n\t) {\n\t\treturn true;\n\t}\n\treturn false;\n}\n\n/**\n * Resolve the default `pnpEnforcement` mode given the bound inputs.\n *\n * Returns `\"on\"` when {@link assessmentHasPnpPolicyInputs} or\n * {@link itemRefHasPnpPolicyInputs} reports any profile policy material; otherwise\n * `\"off\"`. Hosts override the default by passing an explicit\n * `pnpEnforcement` value (engine input) or by calling\n * `ToolkitCoordinator.setPnpEnforcement(\"on\" | \"off\")`.\n */\nexport function resolveDefaultPnpEnforcement(args: {\n\tassessment?: AssessmentEntity | null;\n\tcurrentItemRef?: AssessmentItemRef | null;\n}): \"on\" | \"off\" {\n\tif (assessmentHasPnpPolicyInputs(args.assessment)) return \"on\";\n\tif (itemRefHasPnpPolicyInputs(args.currentItemRef)) return \"on\";\n\treturn \"off\";\n}\n"]}
@@ -1,33 +1,11 @@
1
1
  /**
2
- * Tool Policy Provenance — generalization of `PnpResolutionProvenance`
3
- * (M8 — see `.cursor/plans/m8-design.md` § 4).
2
+ * Tool Policy Provenance (M8 see `.cursor/plans/m8-design.md` § 4).
4
3
  *
5
- * Today's `PnpResolutionProvenance` (in `services/pnp-provenance.ts`)
6
- * tracks decisions made by `PnpToolResolver` only. M8 generalizes the
7
- * shape to track decisions from every Pass-1 contributor — host
8
- * placement, host policy, provider veto, PNP/profile gates, and custom policy
9
- * sources — without losing PNP debugger compatibility.
10
- *
11
- * **Compatibility posture.** This module is the new home of the shape;
12
- * the legacy `pnp-provenance.ts` module remains untouched in PR 1 and
13
- * is deleted in PR 5 (the rip-out PR) once every consumer has migrated
14
- * to the engine. The shape stays structurally compatible: existing
15
- * fields (`contextId`, `resolvedAt`, `sources`, `features`,
16
- * `decisionLog`, `summary`) are preserved verbatim. The rule
17
- * vocabulary expands, and `ResolutionDecision.precedence` widens from
18
- * `1 | 2 | 3 | 4 | 5 | 6` to a `number` so non-profile rules can fit
19
- * (the PNP/profile rules continue to use `1`–`6` exactly as before).
4
+ * Tracks decisions from every Pass-1 contributor: host placement, host policy,
5
+ * provider veto, PNP/profile gates, and custom policy sources.
20
6
  */
21
7
  /**
22
- * Expanded rule vocabulary for `ResolutionDecision.rule` in M8.
23
- *
24
- * The first six values map 1:1 onto `PnpResolutionProvenance`'s
25
- * existing rule names (the PNP/profile precedence ladder). The remaining
26
- * values capture the new contributors the M8 engine surfaces:
27
- * placement membership (step 1), provider veto (step 2), host policy
28
- * (steps 3 / 4), the required-tool conflict diagnostic (`required-tool-blocked`),
29
- * custom sources (step 6), and the catch-all `system-default` for the
30
- * "not configured at any level" fallback.
8
+ * Rule vocabulary for tool policy decisions.
31
9
  */
32
10
  export type ToolPolicyDecisionRule = "district-block" | "test-admin-override" | "item-restriction" | "item-requirement" | "district-requirement" | "pnp-support" | "pnp-prohibited" | "placement-membership" | "provider-disabled" | "host-allowlist" | "host-blocked" | "required-tool-blocked" | "custom-source" | "system-default";
33
11
  export type ToolPolicySourceType = "organization" | "assessment" | "section" | "item" | "student" | "system" | "host" | "custom";
@@ -35,10 +13,8 @@ export interface ToolPolicyResolutionDecision {
35
13
  /** Monotonic step index across the entire decision log. */
36
14
  step: number;
37
15
  /**
38
- * Precedence level. PNP/profile rules use `1`–`6` exactly as in today's
39
- * `PnpResolutionProvenance`. Non-profile rules use `0` (host-side
40
- * gates that always fire before PNP/profile policy) or `7+` (custom sources that
41
- * fire after PNP/profile policy).
16
+ * Precedence level. PNP/profile rules use `1`–`6`; non-profile rules use `0`
17
+ * for host-side gates or `7+` for custom sources that run after PNP/profile policy.
42
18
  */
43
19
  precedence: number;
44
20
  rule: ToolPolicyDecisionRule;
@@ -117,10 +93,7 @@ interface AddDecisionParams {
117
93
  value?: unknown;
118
94
  }
119
95
  /**
120
- * Builder mirroring `PnpProvenanceBuilder` but emitting the expanded
121
- * `ToolPolicyProvenance` shape. Identical API where the field names
122
- * overlap so an `M8 PR 5` rename of the legacy builder is a near-pure
123
- * import-path swap.
96
+ * Builder for `ToolPolicyProvenance`.
124
97
  */
125
98
  export declare class ToolPolicyProvenanceBuilder {
126
99
  private provenance;
@@ -1,28 +1,11 @@
1
1
  /**
2
- * Tool Policy Provenance — generalization of `PnpResolutionProvenance`
3
- * (M8 — see `.cursor/plans/m8-design.md` § 4).
2
+ * Tool Policy Provenance (M8 see `.cursor/plans/m8-design.md` § 4).
4
3
  *
5
- * Today's `PnpResolutionProvenance` (in `services/pnp-provenance.ts`)
6
- * tracks decisions made by `PnpToolResolver` only. M8 generalizes the
7
- * shape to track decisions from every Pass-1 contributor — host
8
- * placement, host policy, provider veto, PNP/profile gates, and custom policy
9
- * sources — without losing PNP debugger compatibility.
10
- *
11
- * **Compatibility posture.** This module is the new home of the shape;
12
- * the legacy `pnp-provenance.ts` module remains untouched in PR 1 and
13
- * is deleted in PR 5 (the rip-out PR) once every consumer has migrated
14
- * to the engine. The shape stays structurally compatible: existing
15
- * fields (`contextId`, `resolvedAt`, `sources`, `features`,
16
- * `decisionLog`, `summary`) are preserved verbatim. The rule
17
- * vocabulary expands, and `ResolutionDecision.precedence` widens from
18
- * `1 | 2 | 3 | 4 | 5 | 6` to a `number` so non-profile rules can fit
19
- * (the PNP/profile rules continue to use `1`–`6` exactly as before).
4
+ * Tracks decisions from every Pass-1 contributor: host placement, host policy,
5
+ * provider veto, PNP/profile gates, and custom policy sources.
20
6
  */
21
7
  /**
22
- * Builder mirroring `PnpProvenanceBuilder` but emitting the expanded
23
- * `ToolPolicyProvenance` shape. Identical API where the field names
24
- * overlap so an `M8 PR 5` rename of the legacy builder is a near-pure
25
- * import-path swap.
8
+ * Builder for `ToolPolicyProvenance`.
26
9
  */
27
10
  export class ToolPolicyProvenanceBuilder {
28
11
  provenance;
@@ -1 +1 @@
1
- {"version":3,"file":"provenance.js","sourceRoot":"","sources":["../../../src/policy/core/provenance.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAkHH;;;;;GAKG;AACH,MAAM,OAAO,2BAA2B;IAC/B,UAAU,CAAuB;IACjC,WAAW,GAAG,CAAC,CAAC;IAExB,YAAY,SAAiB;QAC5B,IAAI,CAAC,UAAU,GAAG;YACjB,SAAS;YACT,UAAU,EAAE,IAAI,IAAI,EAAE;YACtB,OAAO,EAAE,EAAE;YACX,QAAQ,EAAE,IAAI,GAAG,EAAE;YACnB,WAAW,EAAE,EAAE;YACf,OAAO,EAAE;gBACR,aAAa,EAAE,CAAC;gBAChB,OAAO,EAAE,CAAC;gBACV,OAAO,EAAE,CAAC;gBACV,aAAa,EAAE,CAAC;gBAChB,QAAQ,EAAE,EAAE;gBACZ,MAAM,EAAE,EAAE;aACV;SACD,CAAC;IACH,CAAC;IAED,SAAS,CACR,IAA2C,EAC3C,IAAqD;QAErD,MAAM,IAAI,GAAG,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,EAAE,EAAE,CAAC;QACzD,QAAQ,IAAI,EAAE,CAAC;YACd,KAAK,cAAc;gBAClB,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,YAAY,GAAG;oBACtC,GAAG,IAAI;oBACP,WAAW,EAAE,IAAI,CAAC,MAAM;iBACxB,CAAC;gBACF,MAAM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AAI,2BAA2B,CAAC;QAC3C,KAAK,MAAM,CAAC,IAAI,UAAU,EAAE,CAAC;YAC5B,WAAW,IAAI,KAAK,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,MAAM,IAAI,CAAC;QAC7C,CAAC;IACF,CAAC;IACD,OAAO,WAAW,CAAC;AACpB,CAAC","sourcesContent":["/**\n * Tool Policy Provenance — generalization of `PnpResolutionProvenance`\n * (M8 — see `.cursor/plans/m8-design.md` § 4).\n *\n * Today's `PnpResolutionProvenance` (in `services/pnp-provenance.ts`)\n * tracks decisions made by `PnpToolResolver` only. M8 generalizes the\n * shape to track decisions from every Pass-1 contributor — host\n * placement, host policy, provider veto, PNP/profile gates, and custom policy\n * sources — without losing PNP debugger compatibility.\n *\n * **Compatibility posture.** This module is the new home of the shape;\n * the legacy `pnp-provenance.ts` module remains untouched in PR 1 and\n * is deleted in PR 5 (the rip-out PR) once every consumer has migrated\n * to the engine. The shape stays structurally compatible: existing\n * fields (`contextId`, `resolvedAt`, `sources`, `features`,\n * `decisionLog`, `summary`) are preserved verbatim. The rule\n * vocabulary expands, and `ResolutionDecision.precedence` widens from\n * `1 | 2 | 3 | 4 | 5 | 6` to a `number` so non-profile rules can fit\n * (the PNP/profile rules continue to use `1`–`6` exactly as before).\n */\n\n/**\n * Expanded rule vocabulary for `ResolutionDecision.rule` in M8.\n *\n * The first six values map 1:1 onto `PnpResolutionProvenance`'s\n * existing rule names (the PNP/profile precedence ladder). The remaining\n * values capture the new contributors the M8 engine surfaces:\n * placement membership (step 1), provider veto (step 2), host policy\n * (steps 3 / 4), the required-tool conflict diagnostic (`required-tool-blocked`),\n * custom sources (step 6), and the catch-all `system-default` for the\n * \"not configured at any level\" fallback.\n */\nexport type ToolPolicyDecisionRule =\n\t| \"district-block\"\n\t| \"test-admin-override\"\n\t| \"item-restriction\"\n\t| \"item-requirement\"\n\t| \"district-requirement\"\n\t| \"pnp-support\"\n\t| \"pnp-prohibited\"\n\t| \"placement-membership\"\n\t| \"provider-disabled\"\n\t| \"host-allowlist\"\n\t| \"host-blocked\"\n\t| \"required-tool-blocked\"\n\t| \"custom-source\"\n\t| \"system-default\";\n\nexport type ToolPolicySourceType =\n\t| \"organization\"\n\t| \"assessment\"\n\t| \"section\"\n\t| \"item\"\n\t| \"student\"\n\t| \"system\"\n\t| \"host\"\n\t| \"custom\";\n\nexport interface ToolPolicyResolutionDecision {\n\t/** Monotonic step index across the entire decision log. */\n\tstep: number;\n\n\t/**\n\t * Precedence level. PNP/profile rules use `1`–`6` exactly as in today's\n\t * `PnpResolutionProvenance`. Non-profile rules use `0` (host-side\n\t * gates that always fire before PNP/profile policy) or `7+` (custom sources that\n\t * fire after PNP/profile policy).\n\t */\n\tprecedence: number;\n\n\trule: ToolPolicyDecisionRule;\n\n\t/** Tool ID being resolved (post-PNP-support-mapping where applicable). */\n\tfeatureId: string;\n\n\taction: \"block\" | \"enable\" | \"skip\" | \"advisory\";\n\n\tsource: {\n\t\ttype: ToolPolicySourceType;\n\t\tid?: string;\n\t\tname?: string;\n\t};\n\n\treason: string;\n\n\tvalue?: unknown;\n\n\ttimestamp: Date;\n}\n\nexport interface ToolPolicyFeatureTrail {\n\tfeatureId: string;\n\tfinalState: \"enabled\" | \"blocked\" | \"not-configured\" | \"advisory-only\";\n\twinningDecision?: ToolPolicyResolutionDecision;\n\tallDecisions: ToolPolicyResolutionDecision[];\n\texplanation: string;\n}\n\nexport interface ToolPolicyProvenance {\n\tcontextId: string;\n\tresolvedAt: Date;\n\tsources: {\n\t\torganization?: { id: string; name: string; pnpDefaults?: unknown };\n\t\tassessment?: { id: string; name: string; settings?: unknown };\n\t\tsection?: { id: string; title?: string; settings?: unknown };\n\t\titem?: { id: string; name?: string; settings?: unknown };\n\t\tstudent?: { id: string; pnpProfile?: unknown };\n\t\thost?: { id: string; config?: unknown };\n\t};\n\tfeatures: Map<string, ToolPolicyFeatureTrail>;\n\tdecisionLog: ToolPolicyResolutionDecision[];\n\tsummary: {\n\t\ttotalFeatures: number;\n\t\tenabled: number;\n\t\tblocked: number;\n\t\tnotConfigured: number;\n\t\tbySource: Record<string, number>;\n\t\tbyRule: Record<string, number>;\n\t};\n}\n\ninterface AddDecisionParams {\n\tprecedence: number;\n\trule: ToolPolicyDecisionRule;\n\tfeatureId: string;\n\taction: ToolPolicyResolutionDecision[\"action\"];\n\tsourceType: ToolPolicySourceType;\n\tsourceId?: string;\n\tsourceName?: string;\n\treason: string;\n\tvalue?: unknown;\n}\n\n/**\n * Builder mirroring `PnpProvenanceBuilder` but emitting the expanded\n * `ToolPolicyProvenance` shape. Identical API where the field names\n * overlap so an `M8 PR 5` rename of the legacy builder is a near-pure\n * import-path swap.\n */\nexport class ToolPolicyProvenanceBuilder {\n\tprivate provenance: ToolPolicyProvenance;\n\tprivate stepCounter = 0;\n\n\tconstructor(contextId: string) {\n\t\tthis.provenance = {\n\t\t\tcontextId,\n\t\t\tresolvedAt: new Date(),\n\t\t\tsources: {},\n\t\t\tfeatures: new Map(),\n\t\t\tdecisionLog: [],\n\t\t\tsummary: {\n\t\t\t\ttotalFeatures: 0,\n\t\t\t\tenabled: 0,\n\t\t\t\tblocked: 0,\n\t\t\t\tnotConfigured: 0,\n\t\t\t\tbySource: {},\n\t\t\t\tbyRule: {},\n\t\t\t},\n\t\t};\n\t}\n\n\taddSource(\n\t\ttype: keyof ToolPolicyProvenance[\"sources\"],\n\t\tdata: { id: string; name?: string; config?: unknown },\n\t): this {\n\t\tconst base = { id: data.id, name: data.name ?? data.id };\n\t\tswitch (type) {\n\t\t\tcase \"organization\":\n\t\t\t\tthis.provenance.sources.organization = {\n\t\t\t\t\t...base,\n\t\t\t\t\tpnpDefaults: data.config,\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\tcase \"assessment\":\n\t\t\t\tthis.provenance.sources.assessment = {\n\t\t\t\t\t...base,\n\t\t\t\t\tsettings: data.config,\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\tcase \"section\":\n\t\t\t\tthis.provenance.sources.section = { ...base, settings: data.config };\n\t\t\t\tbreak;\n\t\t\tcase \"item\":\n\t\t\t\tthis.provenance.sources.item = { ...base, settings: data.config };\n\t\t\t\tbreak;\n\t\t\tcase \"student\":\n\t\t\t\tthis.provenance.sources.student = {\n\t\t\t\t\tid: data.id,\n\t\t\t\t\tpnpProfile: data.config,\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\tcase \"host\":\n\t\t\t\tthis.provenance.sources.host = { id: data.id, config: data.config };\n\t\t\t\tbreak;\n\t\t}\n\t\treturn this;\n\t}\n\n\taddDecision(params: AddDecisionParams): this {\n\t\tconst decision: ToolPolicyResolutionDecision = {\n\t\t\tstep: ++this.stepCounter,\n\t\t\tprecedence: params.precedence,\n\t\t\trule: params.rule,\n\t\t\tfeatureId: params.featureId,\n\t\t\taction: params.action,\n\t\t\tsource: {\n\t\t\t\ttype: params.sourceType,\n\t\t\t\tid: params.sourceId,\n\t\t\t\tname: params.sourceName,\n\t\t\t},\n\t\t\treason: params.reason,\n\t\t\tvalue: params.value,\n\t\t\ttimestamp: new Date(),\n\t\t};\n\n\t\tthis.provenance.decisionLog.push(decision);\n\n\t\tlet trail = this.provenance.features.get(params.featureId);\n\t\tif (!trail) {\n\t\t\ttrail = {\n\t\t\t\tfeatureId: params.featureId,\n\t\t\t\tfinalState: \"not-configured\",\n\t\t\t\tallDecisions: [],\n\t\t\t\texplanation: \"\",\n\t\t\t};\n\t\t\tthis.provenance.features.set(params.featureId, trail);\n\t\t}\n\t\ttrail.allDecisions.push(decision);\n\n\t\t// \"advisory\" doesn't change finalState — it preserves the existing\n\t\t// blocked/enabled state and only flags a documented conflict.\n\t\tif (params.action === \"advisory\") {\n\t\t\tif (trail.finalState === \"not-configured\") {\n\t\t\t\ttrail.finalState = \"advisory-only\";\n\t\t\t}\n\t\t} else if (params.action !== \"skip\") {\n\t\t\tconst isWinning =\n\t\t\t\t!trail.winningDecision ||\n\t\t\t\tdecision.precedence < trail.winningDecision.precedence;\n\t\t\tif (isWinning) {\n\t\t\t\ttrail.winningDecision = decision;\n\t\t\t\ttrail.finalState = decision.action === \"enable\" ? \"enabled\" : \"blocked\";\n\t\t\t}\n\t\t}\n\n\t\tthis.provenance.summary.bySource[params.sourceType] =\n\t\t\t(this.provenance.summary.bySource[params.sourceType] || 0) + 1;\n\t\tthis.provenance.summary.byRule[params.rule] =\n\t\t\t(this.provenance.summary.byRule[params.rule] || 0) + 1;\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Reconcile every feature's `finalState` against the post-pipeline\n\t * candidate set.\n\t *\n\t * The eager `finalState` updates inside `addDecision` track the\n\t * highest-precedence non-skip decision per feature, but a tool's\n\t * *actual* visibility is only known after step 6 of the\n\t * composition pipeline — earlier decisions can be reversed by\n\t * later host gates, PNP/profile gates, or custom sources. This method\n\t * walks every feature trail and rewrites `finalState` from the\n\t * final candidate set so callers can rely on\n\t * `provenance.features.get(toolId)?.finalState` as the canonical\n\t * \"is this tool visible right now?\" answer (M8 design § 4 + § 12).\n\t *\n\t * Semantics applied per feature:\n\t * - In `survivingIds` → \"enabled\"\n\t * - Not in `survivingIds`, has any non-skip decision → \"blocked\"\n\t * - Not in `survivingIds`, only advisory decisions → \"advisory-only\"\n\t * - Otherwise → \"not-configured\"\n\t *\n\t * Surviving features without any logged decisions get a synthetic\n\t * \"enabled\" trail so the provenance is dense enough for hosts that\n\t * iterate `provenance.features` to find the visible set.\n\t */\n\treconcileFinalStates(survivingIds: ReadonlySet<string>): this {\n\t\tfor (const featureId of survivingIds) {\n\t\t\tlet trail = this.provenance.features.get(featureId);\n\t\t\tif (!trail) {\n\t\t\t\ttrail = {\n\t\t\t\t\tfeatureId,\n\t\t\t\t\tfinalState: \"enabled\",\n\t\t\t\t\tallDecisions: [],\n\t\t\t\t\texplanation: \"\",\n\t\t\t\t};\n\t\t\t\tthis.provenance.features.set(featureId, trail);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\ttrail.finalState = \"enabled\";\n\t\t}\n\n\t\tfor (const trail of this.provenance.features.values()) {\n\t\t\tif (survivingIds.has(trail.featureId)) continue;\n\t\t\tconst hasNonSkip = trail.allDecisions.some(\n\t\t\t\t(d) => d.action !== \"skip\" && d.action !== \"advisory\",\n\t\t\t);\n\t\t\tconst hasAdvisory = trail.allDecisions.some(\n\t\t\t\t(d) => d.action === \"advisory\",\n\t\t\t);\n\t\t\tif (hasNonSkip) {\n\t\t\t\ttrail.finalState = \"blocked\";\n\t\t\t} else if (hasAdvisory) {\n\t\t\t\ttrail.finalState = \"advisory-only\";\n\t\t\t} else {\n\t\t\t\ttrail.finalState = \"not-configured\";\n\t\t\t}\n\t\t}\n\t\treturn this;\n\t}\n\n\tbuild(): ToolPolicyProvenance {\n\t\tfor (const trail of this.provenance.features.values()) {\n\t\t\ttrail.explanation = generateExplanation(trail);\n\t\t}\n\t\tfor (const trail of this.provenance.features.values()) {\n\t\t\tthis.provenance.summary.totalFeatures++;\n\t\t\tif (trail.finalState === \"enabled\") {\n\t\t\t\tthis.provenance.summary.enabled++;\n\t\t\t} else if (trail.finalState === \"blocked\") {\n\t\t\t\tthis.provenance.summary.blocked++;\n\t\t\t} else {\n\t\t\t\tthis.provenance.summary.notConfigured++;\n\t\t\t}\n\t\t}\n\t\treturn this.provenance;\n\t}\n}\n\nfunction generateExplanation(trail: ToolPolicyFeatureTrail): string {\n\tif (!trail.winningDecision) {\n\t\tif (trail.finalState === \"advisory-only\") {\n\t\t\tconst advisory = trail.allDecisions.find((d) => d.action === \"advisory\");\n\t\t\treturn advisory\n\t\t\t\t? `Feature \"${trail.featureId}\" was kept in its host-decided state; ${advisory.reason}`\n\t\t\t\t: `Feature \"${trail.featureId}\" carries an advisory note.`;\n\t\t}\n\t\treturn `Feature \"${trail.featureId}\" was not configured at any level.`;\n\t}\n\n\tconst decision = trail.winningDecision;\n\tconst sourceName = decision.source.name || decision.source.type;\n\tlet explanation = `Feature \"${trail.featureId}\" is ${trail.finalState}.\\n\\n`;\n\texplanation += `**Primary Reason** (${decision.rule}):\\n`;\n\texplanation += `${decision.reason}\\n`;\n\texplanation += `Source: ${sourceName} (${decision.source.type})\\n`;\n\tconst overridden = trail.allDecisions.filter(\n\t\t(d) =>\n\t\t\td.step !== decision.step &&\n\t\t\td.action !== \"skip\" &&\n\t\t\td.action !== \"advisory\" &&\n\t\t\td.precedence > decision.precedence,\n\t);\n\tif (overridden.length > 0) {\n\t\texplanation += `\\n**Overridden Rules**:\\n`;\n\t\tfor (const d of overridden) {\n\t\t\texplanation += `- ${d.rule}: ${d.reason}\\n`;\n\t\t}\n\t}\n\treturn explanation;\n}\n\n"]}
1
+ {"version":3,"file":"provenance.js","sourceRoot":"","sources":["../../../src/policy/core/provenance.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAwGH;;GAEG;AACH,MAAM,OAAO,2BAA2B;IAC/B,UAAU,CAAuB;IACjC,WAAW,GAAG,CAAC,CAAC;IAExB,YAAY,SAAiB;QAC5B,IAAI,CAAC,UAAU,GAAG;YACjB,SAAS;YACT,UAAU,EAAE,IAAI,IAAI,EAAE;YACtB,OAAO,EAAE,EAAE;YACX,QAAQ,EAAE,IAAI,GAAG,EAAE;YACnB,WAAW,EAAE,EAAE;YACf,OAAO,EAAE;gBACR,aAAa,EAAE,CAAC;gBAChB,OAAO,EAAE,CAAC;gBACV,OAAO,EAAE,CAAC;gBACV,aAAa,EAAE,CAAC;gBAChB,QAAQ,EAAE,EAAE;gBACZ,MAAM,EAAE,EAAE;aACV;SACD,CAAC;IACH,CAAC;IAED,SAAS,CACR,IAA2C,EAC3C,IAAqD;QAErD,MAAM,IAAI,GAAG,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,EAAE,EAAE,CAAC;QACzD,QAAQ,IAAI,EAAE,CAAC;YACd,KAAK,cAAc;gBAClB,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,YAAY,GAAG;oBACtC,GAAG,IAAI;oBACP,WAAW,EA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,MAAM,GAAG,CAAC,EAAE,CAAC;QAC3B,WAAW,IAAI,2BAA2B,CAAC;QAC3C,KAAK,MAAM,CAAC,IAAI,UAAU,EAAE,CAAC;YAC5B,WAAW,IAAI,KAAK,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,MAAM,IAAI,CAAC;QAC7C,CAAC;IACF,CAAC;IACD,OAAO,WAAW,CAAC;AACpB,CAAC","sourcesContent":["/**\n * Tool Policy Provenance (M8 — see `.cursor/plans/m8-design.md` § 4).\n *\n * Tracks decisions from every Pass-1 contributor: host placement, host policy,\n * provider veto, PNP/profile gates, and custom policy sources.\n */\n\n/**\n * Rule vocabulary for tool policy decisions.\n */\nexport type ToolPolicyDecisionRule =\n\t| \"district-block\"\n\t| \"test-admin-override\"\n\t| \"item-restriction\"\n\t| \"item-requirement\"\n\t| \"district-requirement\"\n\t| \"pnp-support\"\n\t| \"pnp-prohibited\"\n\t| \"placement-membership\"\n\t| \"provider-disabled\"\n\t| \"host-allowlist\"\n\t| \"host-blocked\"\n\t| \"required-tool-blocked\"\n\t| \"custom-source\"\n\t| \"system-default\";\n\nexport type ToolPolicySourceType =\n\t| \"organization\"\n\t| \"assessment\"\n\t| \"section\"\n\t| \"item\"\n\t| \"student\"\n\t| \"system\"\n\t| \"host\"\n\t| \"custom\";\n\nexport interface ToolPolicyResolutionDecision {\n\t/** Monotonic step index across the entire decision log. */\n\tstep: number;\n\n\t/**\n\t * Precedence level. PNP/profile rules use `1`–`6`; non-profile rules use `0`\n\t * for host-side gates or `7+` for custom sources that run after PNP/profile policy.\n\t */\n\tprecedence: number;\n\n\trule: ToolPolicyDecisionRule;\n\n\t/** Tool ID being resolved (post-PNP-support-mapping where applicable). */\n\tfeatureId: string;\n\n\taction: \"block\" | \"enable\" | \"skip\" | \"advisory\";\n\n\tsource: {\n\t\ttype: ToolPolicySourceType;\n\t\tid?: string;\n\t\tname?: string;\n\t};\n\n\treason: string;\n\n\tvalue?: unknown;\n\n\ttimestamp: Date;\n}\n\nexport interface ToolPolicyFeatureTrail {\n\tfeatureId: string;\n\tfinalState: \"enabled\" | \"blocked\" | \"not-configured\" | \"advisory-only\";\n\twinningDecision?: ToolPolicyResolutionDecision;\n\tallDecisions: ToolPolicyResolutionDecision[];\n\texplanation: string;\n}\n\nexport interface ToolPolicyProvenance {\n\tcontextId: string;\n\tresolvedAt: Date;\n\tsources: {\n\t\torganization?: { id: string; name: string; pnpDefaults?: unknown };\n\t\tassessment?: { id: string; name: string; settings?: unknown };\n\t\tsection?: { id: string; title?: string; settings?: unknown };\n\t\titem?: { id: string; name?: string; settings?: unknown };\n\t\tstudent?: { id: string; pnpProfile?: unknown };\n\t\thost?: { id: string; config?: unknown };\n\t};\n\tfeatures: Map<string, ToolPolicyFeatureTrail>;\n\tdecisionLog: ToolPolicyResolutionDecision[];\n\tsummary: {\n\t\ttotalFeatures: number;\n\t\tenabled: number;\n\t\tblocked: number;\n\t\tnotConfigured: number;\n\t\tbySource: Record<string, number>;\n\t\tbyRule: Record<string, number>;\n\t};\n}\n\ninterface AddDecisionParams {\n\tprecedence: number;\n\trule: ToolPolicyDecisionRule;\n\tfeatureId: string;\n\taction: ToolPolicyResolutionDecision[\"action\"];\n\tsourceType: ToolPolicySourceType;\n\tsourceId?: string;\n\tsourceName?: string;\n\treason: string;\n\tvalue?: unknown;\n}\n\n/**\n * Builder for `ToolPolicyProvenance`.\n */\nexport class ToolPolicyProvenanceBuilder {\n\tprivate provenance: ToolPolicyProvenance;\n\tprivate stepCounter = 0;\n\n\tconstructor(contextId: string) {\n\t\tthis.provenance = {\n\t\t\tcontextId,\n\t\t\tresolvedAt: new Date(),\n\t\t\tsources: {},\n\t\t\tfeatures: new Map(),\n\t\t\tdecisionLog: [],\n\t\t\tsummary: {\n\t\t\t\ttotalFeatures: 0,\n\t\t\t\tenabled: 0,\n\t\t\t\tblocked: 0,\n\t\t\t\tnotConfigured: 0,\n\t\t\t\tbySource: {},\n\t\t\t\tbyRule: {},\n\t\t\t},\n\t\t};\n\t}\n\n\taddSource(\n\t\ttype: keyof ToolPolicyProvenance[\"sources\"],\n\t\tdata: { id: string; name?: string; config?: unknown },\n\t): this {\n\t\tconst base = { id: data.id, name: data.name ?? data.id };\n\t\tswitch (type) {\n\t\t\tcase \"organization\":\n\t\t\t\tthis.provenance.sources.organization = {\n\t\t\t\t\t...base,\n\t\t\t\t\tpnpDefaults: data.config,\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\tcase \"assessment\":\n\t\t\t\tthis.provenance.sources.assessment = {\n\t\t\t\t\t...base,\n\t\t\t\t\tsettings: data.config,\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\tcase \"section\":\n\t\t\t\tthis.provenance.sources.section = { ...base, settings: data.config };\n\t\t\t\tbreak;\n\t\t\tcase \"item\":\n\t\t\t\tthis.provenance.sources.item = { ...base, settings: data.config };\n\t\t\t\tbreak;\n\t\t\tcase \"student\":\n\t\t\t\tthis.provenance.sources.student = {\n\t\t\t\t\tid: data.id,\n\t\t\t\t\tpnpProfile: data.config,\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\tcase \"host\":\n\t\t\t\tthis.provenance.sources.host = { id: data.id, config: data.config };\n\t\t\t\tbreak;\n\t\t}\n\t\treturn this;\n\t}\n\n\taddDecision(params: AddDecisionParams): this {\n\t\tconst decision: ToolPolicyResolutionDecision = {\n\t\t\tstep: ++this.stepCounter,\n\t\t\tprecedence: params.precedence,\n\t\t\trule: params.rule,\n\t\t\tfeatureId: params.featureId,\n\t\t\taction: params.action,\n\t\t\tsource: {\n\t\t\t\ttype: params.sourceType,\n\t\t\t\tid: params.sourceId,\n\t\t\t\tname: params.sourceName,\n\t\t\t},\n\t\t\treason: params.reason,\n\t\t\tvalue: params.value,\n\t\t\ttimestamp: new Date(),\n\t\t};\n\n\t\tthis.provenance.decisionLog.push(decision);\n\n\t\tlet trail = this.provenance.features.get(params.featureId);\n\t\tif (!trail) {\n\t\t\ttrail = {\n\t\t\t\tfeatureId: params.featureId,\n\t\t\t\tfinalState: \"not-configured\",\n\t\t\t\tallDecisions: [],\n\t\t\t\texplanation: \"\",\n\t\t\t};\n\t\t\tthis.provenance.features.set(params.featureId, trail);\n\t\t}\n\t\ttrail.allDecisions.push(decision);\n\n\t\t// \"advisory\" doesn't change finalState — it preserves the existing\n\t\t// blocked/enabled state and only flags a documented conflict.\n\t\tif (params.action === \"advisory\") {\n\t\t\tif (trail.finalState === \"not-configured\") {\n\t\t\t\ttrail.finalState = \"advisory-only\";\n\t\t\t}\n\t\t} else if (params.action !== \"skip\") {\n\t\t\tconst isWinning =\n\t\t\t\t!trail.winningDecision ||\n\t\t\t\tdecision.precedence < trail.winningDecision.precedence;\n\t\t\tif (isWinning) {\n\t\t\t\ttrail.winningDecision = decision;\n\t\t\t\ttrail.finalState = decision.action === \"enable\" ? \"enabled\" : \"blocked\";\n\t\t\t}\n\t\t}\n\n\t\tthis.provenance.summary.bySource[params.sourceType] =\n\t\t\t(this.provenance.summary.bySource[params.sourceType] || 0) + 1;\n\t\tthis.provenance.summary.byRule[params.rule] =\n\t\t\t(this.provenance.summary.byRule[params.rule] || 0) + 1;\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Reconcile every feature's `finalState` against the post-pipeline\n\t * candidate set.\n\t *\n\t * The eager `finalState` updates inside `addDecision` track the\n\t * highest-precedence non-skip decision per feature, but a tool's\n\t * *actual* visibility is only known after step 6 of the\n\t * composition pipeline — earlier decisions can be reversed by\n\t * later host gates, PNP/profile gates, or custom sources. This method\n\t * walks every feature trail and rewrites `finalState` from the\n\t * final candidate set so callers can rely on\n\t * `provenance.features.get(toolId)?.finalState` as the canonical\n\t * \"is this tool visible right now?\" answer (M8 design § 4 + § 12).\n\t *\n\t * Semantics applied per feature:\n\t * - In `survivingIds` → \"enabled\"\n\t * - Not in `survivingIds`, has any non-skip decision → \"blocked\"\n\t * - Not in `survivingIds`, only advisory decisions → \"advisory-only\"\n\t * - Otherwise → \"not-configured\"\n\t *\n\t * Surviving features without any logged decisions get a synthetic\n\t * \"enabled\" trail so the provenance is dense enough for hosts that\n\t * iterate `provenance.features` to find the visible set.\n\t */\n\treconcileFinalStates(survivingIds: ReadonlySet<string>): this {\n\t\tfor (const featureId of survivingIds) {\n\t\t\tlet trail = this.provenance.features.get(featureId);\n\t\t\tif (!trail) {\n\t\t\t\ttrail = {\n\t\t\t\t\tfeatureId,\n\t\t\t\t\tfinalState: \"enabled\",\n\t\t\t\t\tallDecisions: [],\n\t\t\t\t\texplanation: \"\",\n\t\t\t\t};\n\t\t\t\tthis.provenance.features.set(featureId, trail);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\ttrail.finalState = \"enabled\";\n\t\t}\n\n\t\tfor (const trail of this.provenance.features.values()) {\n\t\t\tif (survivingIds.has(trail.featureId)) continue;\n\t\t\tconst hasNonSkip = trail.allDecisions.some(\n\t\t\t\t(d) => d.action !== \"skip\" && d.action !== \"advisory\",\n\t\t\t);\n\t\t\tconst hasAdvisory = trail.allDecisions.some(\n\t\t\t\t(d) => d.action === \"advisory\",\n\t\t\t);\n\t\t\tif (hasNonSkip) {\n\t\t\t\ttrail.finalState = \"blocked\";\n\t\t\t} else if (hasAdvisory) {\n\t\t\t\ttrail.finalState = \"advisory-only\";\n\t\t\t} else {\n\t\t\t\ttrail.finalState = \"not-configured\";\n\t\t\t}\n\t\t}\n\t\treturn this;\n\t}\n\n\tbuild(): ToolPolicyProvenance {\n\t\tfor (const trail of this.provenance.features.values()) {\n\t\t\ttrail.explanation = generateExplanation(trail);\n\t\t}\n\t\tfor (const trail of this.provenance.features.values()) {\n\t\t\tthis.provenance.summary.totalFeatures++;\n\t\t\tif (trail.finalState === \"enabled\") {\n\t\t\t\tthis.provenance.summary.enabled++;\n\t\t\t} else if (trail.finalState === \"blocked\") {\n\t\t\t\tthis.provenance.summary.blocked++;\n\t\t\t} else {\n\t\t\t\tthis.provenance.summary.notConfigured++;\n\t\t\t}\n\t\t}\n\t\treturn this.provenance;\n\t}\n}\n\nfunction generateExplanation(trail: ToolPolicyFeatureTrail): string {\n\tif (!trail.winningDecision) {\n\t\tif (trail.finalState === \"advisory-only\") {\n\t\t\tconst advisory = trail.allDecisions.find((d) => d.action === \"advisory\");\n\t\t\treturn advisory\n\t\t\t\t? `Feature \"${trail.featureId}\" was kept in its host-decided state; ${advisory.reason}`\n\t\t\t\t: `Feature \"${trail.featureId}\" carries an advisory note.`;\n\t\t}\n\t\treturn `Feature \"${trail.featureId}\" was not configured at any level.`;\n\t}\n\n\tconst decision = trail.winningDecision;\n\tconst sourceName = decision.source.name || decision.source.type;\n\tlet explanation = `Feature \"${trail.featureId}\" is ${trail.finalState}.\\n\\n`;\n\texplanation += `**Primary Reason** (${decision.rule}):\\n`;\n\texplanation += `${decision.reason}\\n`;\n\texplanation += `Source: ${sourceName} (${decision.source.type})\\n`;\n\tconst overridden = trail.allDecisions.filter(\n\t\t(d) =>\n\t\t\td.step !== decision.step &&\n\t\t\td.action !== \"skip\" &&\n\t\t\td.action !== \"advisory\" &&\n\t\t\td.precedence > decision.precedence,\n\t);\n\tif (overridden.length > 0) {\n\t\texplanation += `\\n**Overridden Rules**:\\n`;\n\t\tfor (const d of overridden) {\n\t\t\texplanation += `- ${d.rule}: ${d.reason}\\n`;\n\t\t}\n\t}\n\treturn explanation;\n}\n\n"]}
@@ -1,20 +1,11 @@
1
1
  /**
2
- * PNP Policy Source — refactor of `PnpToolResolver` for the M8 engine
3
- * (see `.cursor/plans/m8-design.md` § 3 step 5 and § 5 §).
2
+ * PNP Policy Source for the M8 engine
3
+ * (see `.cursor/plans/m8-design.md` § 3 step 5 and § 5).
4
4
  *
5
- * This source applies the PNP/profile precedence rules used by today's
6
- * `PnpToolResolver` but exposes them as a `(candidates, pnpPolicyInputs) →
5
+ * This source applies the PNP/profile precedence rules as a `(candidates, pnpPolicyInputs) →
7
6
  * (refinedCandidates, perToolFlags, mandates, decisions)` function the
8
7
  * engine can call once per `decide(...)` request, with all results
9
8
  * routed through the unified `ToolPolicyProvenanceBuilder`.
10
- *
11
- * **Why this lives next to the legacy resolver instead of replacing
12
- * it.** PR 1 introduces the engine without callers; the legacy
13
- * `PnpToolResolver` is still in active use by `<pie-item-toolbar>`
14
- * and by external tests. PR 5 deletes the legacy class once the
15
- * toolbar (PR 3) and the PNP default flip (PR 4) have landed and the
16
- * caller list is empty. Until then this source is the *canonical*
17
- * implementation and the legacy class is the deprecated mirror.
18
9
  */
19
10
  import type { AssessmentEntity, AssessmentItemRef } from "@pie-players/pie-players-shared/types";
20
11
  import type { ToolRegistry } from "../../services/ToolRegistry.js";
@@ -122,24 +113,20 @@ export declare class PnpPolicySource {
122
113
  * strings for tools the registry does not (yet) carry without
123
114
  * losing them in policy evaluation.
124
115
  *
125
- * The legacy `PnpToolResolver.resolveTool` had the same behavior;
126
- * see `tests/policy/PnpPolicySource.test.ts` for the regression
127
- * lock.
116
+ * `tests/policy/PnpPolicySource.test.ts` locks this mapping behavior.
128
117
  */
129
118
  private mapSupportToToolId;
130
119
  /**
131
120
  * Resolve tool-specific settings, item-level taking precedence over
132
121
  * assessment-level.
133
122
  *
134
- * Uses `??` (nullish-coalescing) rather than the legacy resolver's
135
- * `||`. Tool config values are typed `unknown` and may legitimately
123
+ * Uses `??` (nullish-coalescing). Tool config values are typed `unknown` and may legitimately
136
124
  * be `false` / `0` / `""` (e.g. a tool whose canonical "off" config
137
125
  * is the literal `false`). `||` would treat those as missing and
138
126
  * silently fall through to the assessment-level config, masking the
139
127
  * authored item-level intent. `??` only falls through on
140
128
  * `null`/`undefined`, which matches the semantic of "value not
141
- * provided." This is a deliberate behavior delta from the legacy
142
- * `PnpToolResolver` (M8 PR 1).
129
+ * provided."
143
130
  */
144
131
  private resolveToolSettings;
145
132
  }
@@ -1,20 +1,11 @@
1
1
  /**
2
- * PNP Policy Source — refactor of `PnpToolResolver` for the M8 engine
3
- * (see `.cursor/plans/m8-design.md` § 3 step 5 and § 5 §).
2
+ * PNP Policy Source for the M8 engine
3
+ * (see `.cursor/plans/m8-design.md` § 3 step 5 and § 5).
4
4
  *
5
- * This source applies the PNP/profile precedence rules used by today's
6
- * `PnpToolResolver` but exposes them as a `(candidates, pnpPolicyInputs) →
5
+ * This source applies the PNP/profile precedence rules as a `(candidates, pnpPolicyInputs) →
7
6
  * (refinedCandidates, perToolFlags, mandates, decisions)` function the
8
7
  * engine can call once per `decide(...)` request, with all results
9
8
  * routed through the unified `ToolPolicyProvenanceBuilder`.
10
- *
11
- * **Why this lives next to the legacy resolver instead of replacing
12
- * it.** PR 1 introduces the engine without callers; the legacy
13
- * `PnpToolResolver` is still in active use by `<pie-item-toolbar>`
14
- * and by external tests. PR 5 deletes the legacy class once the
15
- * toolbar (PR 3) and the PNP default flip (PR 4) have landed and the
16
- * caller list is empty. Until then this source is the *canonical*
17
- * implementation and the legacy class is the deprecated mirror.
18
9
  */
19
10
  export class PnpPolicySource {
20
11
  id = "pnp";
@@ -239,9 +230,7 @@ export class PnpPolicySource {
239
230
  * strings for tools the registry does not (yet) carry without
240
231
  * losing them in policy evaluation.
241
232
  *
242
- * The legacy `PnpToolResolver.resolveTool` had the same behavior;
243
- * see `tests/policy/PnpPolicySource.test.ts` for the regression
244
- * lock.
233
+ * `tests/policy/PnpPolicySource.test.ts` locks this mapping behavior.
245
234
  */
246
235
  mapSupportToToolId(supportId) {
247
236
  const toolIds = this.toolRegistry.getToolsByPNPSupport(supportId);
@@ -253,15 +242,13 @@ export class PnpPolicySource {
253
242
  * Resolve tool-specific settings, item-level taking precedence over
254
243
  * assessment-level.
255
244
  *
256
- * Uses `??` (nullish-coalescing) rather than the legacy resolver's
257
- * `||`. Tool config values are typed `unknown` and may legitimately
245
+ * Uses `??` (nullish-coalescing). Tool config values are typed `unknown` and may legitimately
258
246
  * be `false` / `0` / `""` (e.g. a tool whose canonical "off" config
259
247
  * is the literal `false`). `||` would treat those as missing and
260
248
  * silently fall through to the assessment-level config, masking the
261
249
  * authored item-level intent. `??` only falls through on
262
250
  * `null`/`undefined`, which matches the semantic of "value not
263
- * provided." This is a deliberate behavior delta from the legacy
264
- * `PnpToolResolver` (M8 PR 1).
251
+ * provided."
265
252
  */
266
253
  resolveToolSettings(supportId, ctx) {
267
254
  return (ctx.itemSettings?.toolParameters?.[supportId] ??