mcard-studio 0.0.2 → 0.0.3

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 (196) hide show
  1. package/README.md +3 -0
  2. package/astro.config.mjs +41 -2
  3. package/cli/lib/runtimeContext.mjs +6 -3
  4. package/dist/client/_astro/{ChartAnalyticsViewlet.jrwIemvb.js → ChartAnalyticsViewlet.CBW-JyA3.js} +1 -1
  5. package/dist/client/_astro/{ClmPcardViewlet.C-fU7oZf.js → ClmPcardViewlet.cvKsR2ng.js} +2 -2
  6. package/dist/client/_astro/{D3GraphViewlet.BCZl0b2U.js → D3GraphViewlet.8YEIrCGL.js} +1 -1
  7. package/dist/client/_astro/DockviewSpatialWorkbench.BTd66LPl.js +12 -0
  8. package/dist/client/_astro/DocumentViewlets.KY1HcNka.js +2 -0
  9. package/dist/client/_astro/DxfViewlet.B3N5zpZR.js +1 -0
  10. package/dist/client/_astro/{ExcalidrawWhiteboardViewlet.CFpPYSdn.js → ExcalidrawWhiteboardViewlet.CMJGCQN4.js} +1 -1
  11. package/dist/client/_astro/{FaroVCardSpanInstrumenter.un8kDMWv.js → FaroVCardSpanInstrumenter.ClIqZujq.js} +1 -1
  12. package/dist/client/_astro/{FontSpecimenViewlet.D7Aw2xBZ.js → FontSpecimenViewlet.ChIyr0B8.js} +1 -1
  13. package/dist/client/_astro/HeadMeta.astro_astro_type_script_index_0_lang.D3FSc061.js +1 -0
  14. package/dist/client/_astro/{ImageViewlet.D4FN87n_.js → ImageViewlet.Cs-u7-wt.js} +1 -1
  15. package/dist/client/_astro/{KatexFormulaViewlet.CzhdIOw8.js → KatexFormulaViewlet.0nOzV_qD.js} +1 -1
  16. package/dist/client/_astro/{KoishiChatViewlet.5mepQvLX.js → KoishiChatViewlet.DLsMmwdb.js} +4 -4
  17. package/dist/client/_astro/{MCardLibraryHarness.DE8KeghO.js → MCardLibraryHarness.WBT9W10S.js} +1 -1
  18. package/dist/client/_astro/{MarkdownViewlet.CRuuXXmF.js → MarkdownViewlet.BIolkNXf.js} +25 -25
  19. package/dist/client/_astro/{MermaidDiagramViewlet.eW6sk-rF.js → MermaidDiagramViewlet.CkRk7QsS.js} +1 -1
  20. package/dist/client/_astro/PCardRendererBridge.DhaRSprd.js +1 -0
  21. package/dist/client/_astro/RendererPCardRegistry.brM2KiQs.js +1 -0
  22. package/dist/client/_astro/{SchemaYamlViewlet.ZJBvxItR.js → SchemaYamlViewlet.Bc7nkK4M.js} +1 -1
  23. package/dist/client/_astro/{ShellContainer.astro_astro_type_script_index_0_lang.j_ELcN5d.js → ShellContainer.astro_astro_type_script_index_0_lang.5q1gCLvf.js} +1 -1
  24. package/dist/client/_astro/{Spatial3dViewlet.DnVMBENJ.js → Spatial3dViewlet.C-jjhr0A.js} +1 -1
  25. package/dist/client/_astro/{StudioLayout.CBgiVbeb.css → StudioLayout.CX8XGtZV.css} +1 -1
  26. package/dist/client/_astro/StudioWorkbench.B1QwGHWM.js +7 -0
  27. package/dist/client/_astro/{SvgViewlet.BCje7Qqb.js → SvgViewlet.uGxvb06H.js} +1 -1
  28. package/dist/client/_astro/{TerminalView.C_Ksz6lT.js → TerminalView.DP7G7E1m.js} +1 -1
  29. package/dist/client/_astro/{ThemeSettingsViewlet.DJpjQQ0Z.js → ThemeSettingsViewlet.UaTHcGnF.js} +1 -1
  30. package/dist/client/_astro/{TikzDiagramViewlet.CXb1A8nf.js → TikzDiagramViewlet.O8MJyXfT.js} +1 -1
  31. package/dist/client/_astro/VideoPlayerViewlet.-ycmo3kY.js +1 -0
  32. package/dist/client/_astro/WebappZenViewlet.PNce4u2T.js +1 -0
  33. package/dist/client/_astro/{WelcomeViewport.BiYwLh6l.js → WelcomeViewport.CZ6RxGSw.js} +1 -1
  34. package/dist/client/_astro/{agentIdentityCredentialService.UzMMwBwv.js → agentIdentityCredentialService.BEtZzBlO.js} +1 -1
  35. package/dist/client/_astro/cardTypeDetector.C2HH5RnU.js +1 -0
  36. package/dist/client/_astro/disposable.BmlxZrDf.js +1 -0
  37. package/dist/client/_astro/{markdownService.BgWjyJ57.js → markdownService.CpuKl0vp.js} +1 -1
  38. package/dist/client/_astro/{mcardStore.CT-ollfl.js → mcardStore.nSWnzeLg.js} +1 -1
  39. package/dist/client/_astro/mcardVfs.BSdys1Y7.js +3 -0
  40. package/dist/client/_astro/pathsConfig.CSBBSzwH.js +2 -0
  41. package/dist/client/_astro/{polyfills._3wYPjZf.js → polyfills.Bi7kO8cu.js} +1 -1
  42. package/dist/client/_astro/rendererEventBus.DirFDmGw.js +1 -0
  43. package/dist/client/_astro/themeStore.BajxvCga.js +1 -0
  44. package/dist/client/_astro/{tikzCompiler.fe3qomFY.js → tikzCompiler.-fXMNQpz.js} +1 -1
  45. package/dist/client/_astro/{useMCardHydration.7Z-HfBh5.js → useMCardHydration.Bjj_N5Gv.js} +1 -1
  46. package/dist/client/_astro/vendor-clm-kernel.B0kxq3g4.js +108 -0
  47. package/dist/client/_astro/{vfsHandles.IX_wTpw_.js → vfsHandles.D4Pq18pW.js} +1 -1
  48. package/dist/client/_astro/vfsPersistence.DVrd1BZj.js +1 -0
  49. package/dist/client/_astro/{vfsTransactions.C_IQQg0s.js → vfsTransactions.DBNtFuRz.js} +1 -1
  50. package/dist/client/_astro/{workspaceStore.CD0kAVAl.js → workspaceStore.DUHW2YBc.js} +1 -1
  51. package/dist/server/chunks/{_.._5gPhVOLM.mjs → _.._CoQKwo62.mjs} +137 -91
  52. package/dist/server/chunks/{_handle__D_cIJYrU.mjs → _handle__D8dKQPUS.mjs} +3 -3
  53. package/dist/server/chunks/{cardTypeDetector_CyW1Xnmy.mjs → cardTypeDetector_C55M_HWS.mjs} +9 -0
  54. package/dist/server/chunks/{cards_B89BvF6W.mjs → cards_rVOc8K6H.mjs} +2 -2
  55. package/dist/server/chunks/cas_DTxlZ4Le.mjs +68 -0
  56. package/dist/server/chunks/{dispatch_DOwSKukU.mjs → dispatch_BTW4E_BJ.mjs} +8 -7
  57. package/dist/server/chunks/{dispatch_CxWKiHpn.mjs → dispatch_MbkljUxD.mjs} +8 -8
  58. package/dist/server/chunks/{export_DRouradA.mjs → export_DkEwDE2T.mjs} +3 -3
  59. package/dist/server/chunks/{health_Dfa5I0-X.mjs → health_cRt0M0yu.mjs} +1 -1
  60. package/dist/server/chunks/{mcard-library_7Wzoihkm.mjs → mcard-library_CLHvyslV.mjs} +1 -1
  61. package/dist/server/chunks/{mcardVfs_CeezzRvt.mjs → mcardVfs_DvNburKb.mjs} +5 -30
  62. package/dist/server/chunks/{move__RFvIDkq.mjs → move_DYcaXBLV.mjs} +6 -6
  63. package/dist/server/chunks/{pathsConfig_CgNYYLVm.mjs → pathsConfig_Dack-p2f.mjs} +13 -3
  64. package/dist/server/chunks/{proxy_CrWJQIBe.mjs → proxy_CMbbdBPW.mjs} +2 -2
  65. package/dist/server/chunks/{raw_DzNDaDVP.mjs → raw_C97sJWhg.mjs} +59 -26
  66. package/dist/server/chunks/{serverBootstrap_XKo2s6Ha.mjs → serverBootstrap_BDdSRIu5.mjs} +2 -2
  67. package/dist/server/chunks/tree_BwmO-pTe.mjs +186 -0
  68. package/dist/server/chunks/vfsCore_DIKpk-pk.mjs +98 -0
  69. package/dist/server/chunks/{vfsTreeScan_CKp7kMt9.mjs → vfsTreeScan_CRoCluPB.mjs} +18 -10
  70. package/dist/server/chunks/workspaceRoot_CRx3taID.mjs +157 -0
  71. package/dist/server/chunks/{write_popiFsO7.mjs → write_BLsmsTIx.mjs} +6 -5
  72. package/dist/server/chunks/{ws-server-init_DUjuR2-o.mjs → ws-server-init_Cfft7U5u.mjs} +343 -298
  73. package/dist/server/entry.mjs +1 -1
  74. package/dist/server/entry2.mjs +67 -28
  75. package/dist/server/virtual_astro_middleware.mjs +2 -2
  76. package/package.json +2 -2
  77. package/src/components/studio/views/cardViewlets/ClmRegistryComponentViewlet.tsx +133 -0
  78. package/src/components/studio/views/cardViewlets/DxfViewlet.tsx +230 -0
  79. package/src/components/studio/views/cardViewlets/VideoPlayerViewlet.tsx +4 -4
  80. package/src/components/studio/views/cardViewlets/coreViewletDefs.ts +2 -2
  81. package/src/components/studio/views/cardViewlets/documents/AudioPlayerViewlet.tsx +15 -3
  82. package/src/components/studio/views/cardViewlets/documents/PdfViewlet.tsx +25 -7
  83. package/src/components/studio/views/cardViewlets/markdown/stages/wikilinkStage.ts +2 -1
  84. package/src/components/studio/views/cardViewlets/mediaViewletDefs.ts +21 -1
  85. package/src/components/studio/views/cardViewlets/webapp/WebappCanvas.tsx +40 -15
  86. package/src/components/studio/views/cardViewlets/webapp/WebappDevicePresetBar.tsx +108 -0
  87. package/src/components/studio/views/cardViewlets/webapp/WebappZenViewlet.tsx +23 -30
  88. package/src/components/studio/views/fileTree/MCardFileTree.tsx +71 -54
  89. package/src/components/studio/views/fileTree/hooks/useFileTreeSync.ts +0 -1
  90. package/src/components/studio/views/fileTree/hooks/usePartitionedTrees.ts +68 -23
  91. package/src/components/studio/views/fileTree/hooks/useSectionAccordion.ts +21 -11
  92. package/src/components/studio/views/functions/UnifiedFunctionExplorerViewlet.tsx +168 -0
  93. package/src/components/studio/views/history/HistoryPanel.tsx +110 -0
  94. package/src/components/studio/views/lineage/LineagePanel.tsx +152 -0
  95. package/src/components/studio/views/navigation/HandleLineageDrawer.tsx +89 -0
  96. package/src/components/studio/views/navigation/MultiCardCollectionBrowser.tsx +154 -0
  97. package/src/components/studio/views/pills/HashPill.tsx +101 -0
  98. package/src/components/studio/views/residency/ResidencyIndicator.tsx +82 -0
  99. package/src/config/app_config.json +3 -3
  100. package/src/core/projection/catalog.ts +105 -0
  101. package/src/core/projection/collection.ts +148 -0
  102. package/src/core/projection/handleSubscription.ts +132 -0
  103. package/src/core/projection/index.ts +4 -0
  104. package/src/core/projection/selectors.ts +29 -0
  105. package/src/core/projection/views.ts +242 -0
  106. package/src/core/refinement/designMetrics.ts +104 -0
  107. package/src/core/refinement/fibrationProjector.ts +142 -0
  108. package/src/core/refinement/lagrangianEngine.ts +137 -0
  109. package/src/core/refinement/refinementCommands.ts +82 -0
  110. package/src/core/viewport/deviceArchetypeRegistry.ts +177 -0
  111. package/src/core/viewport/viewportAudit.ts +150 -0
  112. package/src/edge/storeFilter.d.ts +4 -0
  113. package/src/edge/storeFilter.js +54 -0
  114. package/src/edge/storeFilter.ts +52 -0
  115. package/src/lib/cryptoPolyfill.js +77 -1
  116. package/src/lib/fsPolyfill.js +65 -0
  117. package/src/lib/urlPolyfill.js +21 -0
  118. package/src/lib/zlibPolyfill.js +35 -0
  119. package/src/packages/mcard-studio/package.json +2 -2
  120. package/src/packages/mcard-studio/type/legacyMapping.ts +5 -0
  121. package/src/packages/mcard-studio/viewlets/manifests.ts +2 -0
  122. package/src/packages/mcard-studio/viewlets/moduleMap.ts +12 -0
  123. package/src/packages/mcard-studio/viewlets/refinementManifests.ts +114 -0
  124. package/src/pages/api/dispatch.ts +3 -2
  125. package/src/pages/api/vfs/cas.ts +114 -0
  126. package/src/pages/api/vfs/move.ts +5 -5
  127. package/src/pages/api/vfs/raw.ts +72 -27
  128. package/src/pages/api/vfs/tree.ts +130 -11
  129. package/src/pages/api/vfs/write.ts +5 -4
  130. package/src/server/api/kernelDispatch.ts +8 -8
  131. package/src/server/artifactCollectionService.ts +4 -7
  132. package/src/server/artifactRepository.ts +4 -3
  133. package/src/server/clmRunner.mjs +1 -1
  134. package/src/server/collectionOwner.mjs +5 -5
  135. package/src/server/effects/executionPersistenceService.mjs +11 -11
  136. package/src/server/effects/resultSealingService.mjs +2 -2
  137. package/src/server/fileIngestService.mjs +21 -9
  138. package/src/server/fileWatcherService.mjs +4 -1
  139. package/src/server/handlers/fileChangeHandler.mjs +18 -10
  140. package/src/server/handlers/saveExecutionLogHandler.mjs +6 -6
  141. package/src/server/notificationService.mjs +14 -1
  142. package/src/server/scripts/buildSeedingMemory.mjs +3 -3
  143. package/src/server/serverMemoryRepository.ts +41 -59
  144. package/src/server/vfsTreeScan.ts +16 -10
  145. package/src/server/workspaceRoot.ts +143 -5
  146. package/src/services/cardTypeDetector.ts +4 -0
  147. package/src/services/databaseSyncService.ts +30 -46
  148. package/src/services/namespaceProtocolClient.ts +221 -0
  149. package/src/services/renderers/pcard/RendererPCardRegistry.ts +4 -66
  150. package/src/services/renderers/pcard/modalitySpecs.ts +125 -0
  151. package/src/services/renderers/pcard/types.ts +7 -1
  152. package/src/services/renderers/rendererEventBus.ts +5 -3
  153. package/src/services/unifiedFunctionExecutionService.ts +145 -0
  154. package/src/services/vfs/vfsCore.ts +12 -1
  155. package/src/services/vfs/vfsMigration.ts +95 -0
  156. package/src/services/vfs/vfsMutations.ts +17 -35
  157. package/src/services/vfs/vfsPersistence.ts +19 -24
  158. package/src/services/vfs/vfsSync.ts +55 -17
  159. package/src/services/vfs/vfsVersions.ts +23 -34
  160. package/src/services/workbenchExecutionPolicy.ts +183 -0
  161. package/src/stores/mcardCollectionStore.ts +2 -0
  162. package/src/styles/dockview.css +34 -0
  163. package/src/ui/viewlets/FibrationRefinementViewlet.tsx +155 -0
  164. package/src/ui/viewlets/PetriConformanceViewlet.tsx +166 -0
  165. package/src/ui/viewlets/ResponsiveViewportLabViewlet.tsx +175 -0
  166. package/src/ui/viewlets/SprintGovernanceViewlet.tsx +176 -0
  167. package/src/ui/viewlets/viewletFocus.ts +35 -0
  168. package/src/ui/viewlets/viewportLabParts.tsx +190 -0
  169. package/dist/client/_astro/DockviewSpatialWorkbench.B_I1GJHw.js +0 -12
  170. package/dist/client/_astro/DocumentViewlets.B53IqmpY.js +0 -2
  171. package/dist/client/_astro/HeadMeta.astro_astro_type_script_index_0_lang.VDRYJCM-.js +0 -1
  172. package/dist/client/_astro/PCardRendererBridge.oxVKc0gN.js +0 -1
  173. package/dist/client/_astro/RendererPCardRegistry.CWjYZs2H.js +0 -1
  174. package/dist/client/_astro/StudioWorkbench.Blo5oSIw.js +0 -7
  175. package/dist/client/_astro/VideoPlayerViewlet.CmECt7yT.js +0 -1
  176. package/dist/client/_astro/WebappZenViewlet.whCmGVHR.js +0 -1
  177. package/dist/client/_astro/__vite-browser-external.CQZnr-r3.js +0 -1
  178. package/dist/client/_astro/cardTypeDetector.Ci4APwhX.js +0 -1
  179. package/dist/client/_astro/disposable.Dsb0sbRP.js +0 -1
  180. package/dist/client/_astro/mcardVfs.2UOw9Z-r.js +0 -3
  181. package/dist/client/_astro/pathsConfig.D0hV34p7.js +0 -2
  182. package/dist/client/_astro/rendererEventBus.DMH9afq9.js +0 -1
  183. package/dist/client/_astro/themeStore.CEt0e54l.js +0 -1
  184. package/dist/client/_astro/vendor-clm-kernel.Bvk3XHk2.js +0 -116
  185. package/dist/client/_astro/vfsPersistence.BuhXYeSb.js +0 -1
  186. package/dist/server/chunks/cryptoPolyfill_99rxUwYC.mjs +0 -180
  187. package/dist/server/chunks/kernelHash_DRaj51hY.mjs +0 -5
  188. package/dist/server/chunks/tree_CE2BhvyJ.mjs +0 -76
  189. package/dist/server/chunks/vfsCore_B6nCiBl5.mjs +0 -21
  190. package/dist/server/chunks/workspaceRoot_DVSUbYkd.mjs +0 -71
  191. package/src/server/kernelHash.ts +0 -22
  192. package/src/server/storage/cardCollection.ts +0 -94
  193. package/src/server/storage/index.ts +0 -3
  194. package/src/server/storage/mcard.ts +0 -99
  195. package/src/server/storage/sqliteNodeEngine.ts +0 -121
  196. /package/dist/server/chunks/{StudioLayout_B5ZnlqjF.mjs → StudioLayout_taayQJ5b.mjs} +0 -0
@@ -0,0 +1,82 @@
1
+ /**
2
+ * src/core/refinement/refinementCommands.ts
3
+ * Slash-command surface for the refinement inspectors (SMR-11 · DoD-SMR-11-06).
4
+ *
5
+ * `KoishiChatConsole` accepts `/inspect-fiber`, `/lagrangian-check`, and
6
+ * `/sprint-governance`; each opens and focuses one inspector viewlet. The parser is
7
+ * pure — it returns an intent, and the UI layer performs the focus — so command
8
+ * dispatch is unit-testable without a console.
9
+ *
10
+ * Contract D budget: <= 250 LOC.
11
+ */
12
+
13
+ export interface RefinementCommand {
14
+ readonly command: string;
15
+ readonly viewlet: string;
16
+ /** The renderer PCard handle the command focuses. */
17
+ readonly handle: string;
18
+ readonly description: string;
19
+ readonly aliases?: readonly string[];
20
+ }
21
+
22
+ export const REFINEMENT_COMMANDS: readonly RefinementCommand[] = [
23
+ {
24
+ command: '/inspect-fiber',
25
+ viewlet: 'PetriConformanceViewlet',
26
+ handle: 'pcard:render/petri-inspector',
27
+ description: 'Open the Petri marking and fiber conformance inspector',
28
+ aliases: ['/inspect-fibers', '/fiber-conformance'],
29
+ },
30
+ {
31
+ command: '/lagrangian-check',
32
+ viewlet: 'FibrationRefinementViewlet',
33
+ handle: 'pcard:render/fibration-dashboard',
34
+ description: 'Open the Least-Action & Fibration dashboard',
35
+ aliases: ['/lagrangian', '/least-action'],
36
+ },
37
+ {
38
+ command: '/sprint-governance',
39
+ viewlet: 'SprintGovernanceViewlet',
40
+ handle: 'pcard:render/sprint-governance',
41
+ description: 'Open the sprint registry and deployment budget inspector',
42
+ aliases: ['/sprints', '/governance'],
43
+ },
44
+ ];
45
+
46
+ export type RefinementCommandIntent =
47
+ | { readonly kind: 'open-viewlet'; readonly command: string; readonly viewlet: string; readonly handle: string }
48
+ | { readonly kind: 'unknown'; readonly command: string; readonly suggestions: readonly string[] }
49
+ | { readonly kind: 'none' };
50
+
51
+ /** Looks a command (or one of its aliases) up, case-insensitively. */
52
+ export function findRefinementCommand(token: string): RefinementCommand | null {
53
+ const needle = token.trim().toLowerCase();
54
+ if (!needle) return null;
55
+ return (
56
+ REFINEMENT_COMMANDS.find(
57
+ (entry) =>
58
+ entry.command.toLowerCase() === needle ||
59
+ (entry.aliases ?? []).some((alias) => alias.toLowerCase() === needle),
60
+ ) ?? null
61
+ );
62
+ }
63
+
64
+ /**
65
+ * Parses console input. A non-slash message is `none` (the chat handles it); an
66
+ * unrecognised slash command is `unknown` with the known commands as suggestions, so
67
+ * the console can answer instead of silently swallowing it.
68
+ */
69
+ export function parseRefinementCommand(input: string): RefinementCommandIntent {
70
+ const text = String(input ?? '').trim();
71
+ if (!text.startsWith('/')) return { kind: 'none' };
72
+ const token = text.split(/\s+/)[0];
73
+ const entry = findRefinementCommand(token);
74
+ if (!entry) {
75
+ return {
76
+ kind: 'unknown',
77
+ command: token,
78
+ suggestions: REFINEMENT_COMMANDS.map((command) => command.command),
79
+ };
80
+ }
81
+ return { kind: 'open-viewlet', command: entry.command, viewlet: entry.viewlet, handle: entry.handle };
82
+ }
@@ -0,0 +1,177 @@
1
+ /**
2
+ * deviceArchetypeRegistry.ts — The Four Responsive Device Archetype Classes
3
+ * Canonical Path: src/core/viewport/deviceArchetypeRegistry.ts
4
+ * Program: EPIC-SMR · Sprint: SMR-12 (DoD-SMR-12-01) · Invariants: INV-SMR-06, INV-RVP-03
5
+ *
6
+ * Pure, zero-DOM port of `LandingPage/js/device-registry.js`: the dimension
7
+ * contract, the derived aspect ratio, the containment scale math, and the
8
+ * 90° portrait/landscape swap are preserved, and the registry is extended with
9
+ * the four canonical device classes (wearable, cellphone, laptop, desktop),
10
+ * their resource budgets, and their ergonomic touch-target minimums.
11
+ *
12
+ * Nothing here touches the DOM, storage, or the network — the viewlet renders,
13
+ * this module decides. Contract D budget: <= 200 LOC.
14
+ */
15
+
16
+ export type DeviceClassId = 'wearable' | 'cellphone' | 'laptop' | 'desktop';
17
+
18
+ /** INV-RVP-03: the closed dimension contract, inherited from the LandingPage lab. */
19
+ export const DIM_MIN = 100;
20
+ export const DIM_MAX = 7680;
21
+
22
+ export interface DeviceClass {
23
+ readonly id: DeviceClassId;
24
+ readonly label: string;
25
+ /** Maximum page payload the class may receive, in bytes. */
26
+ readonly maxBytes: number;
27
+ /** Minimum comfortable touch target in CSS px; null when the class is pointer-driven. */
28
+ readonly minTouchTarget: number | null;
29
+ readonly orientation: 'portrait' | 'landscape' | 'either';
30
+ readonly input: string;
31
+ /** INV-SMR-06: every class must render without horizontal overflow. */
32
+ readonly maxHorizontalOverflow: number;
33
+ }
34
+
35
+ const MB = 1024 * 1024;
36
+
37
+ export const DEVICE_CLASSES: Readonly<Record<DeviceClassId, DeviceClass>> = Object.freeze({
38
+ wearable: {
39
+ id: 'wearable',
40
+ label: 'Wearable',
41
+ maxBytes: 2 * MB,
42
+ minTouchTarget: 48,
43
+ orientation: 'either',
44
+ input: 'Crown scroll & tap; high-contrast glanceable UI',
45
+ maxHorizontalOverflow: 0,
46
+ },
47
+ cellphone: {
48
+ id: 'cellphone',
49
+ label: 'Cellphone',
50
+ maxBytes: 5 * MB,
51
+ minTouchTarget: 44,
52
+ orientation: 'either',
53
+ input: 'Touch & swipe; collapsible sovereign pill HUD',
54
+ maxHorizontalOverflow: 0,
55
+ },
56
+ laptop: {
57
+ id: 'laptop',
58
+ label: 'Laptop',
59
+ maxBytes: 15 * MB,
60
+ minTouchTarget: null,
61
+ orientation: 'landscape',
62
+ input: 'Keyboard + trackpad; full focus-ring navigation',
63
+ maxHorizontalOverflow: 0,
64
+ },
65
+ desktop: {
66
+ id: 'desktop',
67
+ label: 'Desktop',
68
+ maxBytes: 25 * MB,
69
+ minTouchTarget: null,
70
+ orientation: 'landscape',
71
+ input: 'Multi-window, high-density canvas; edge-to-edge membrane',
72
+ maxHorizontalOverflow: 0,
73
+ },
74
+ });
75
+
76
+ export const DEVICE_CLASS_IDS: readonly DeviceClassId[] = ['wearable', 'cellphone', 'laptop', 'desktop'];
77
+
78
+ export interface DevicePreset {
79
+ readonly id: string;
80
+ readonly label: string;
81
+ readonly deviceClass: DeviceClassId;
82
+ readonly width: number;
83
+ readonly height: number;
84
+ readonly pixelRatio: number;
85
+ }
86
+
87
+ /** The eight canonical hardware presets, two per class. Dimensions are portrait. */
88
+ export const DEVICE_PRESETS: readonly DevicePreset[] = Object.freeze([
89
+ { id: 'watch-compact', label: 'Watch Compact', deviceClass: 'wearable', width: 198, height: 242, pixelRatio: 2 },
90
+ { id: 'watch-large', label: 'Watch Large / Spatial HUD', deviceClass: 'wearable', width: 368, height: 448, pixelRatio: 2 },
91
+ { id: 'mobile-standard', label: 'Mobile Standard', deviceClass: 'cellphone', width: 375, height: 812, pixelRatio: 3 },
92
+ { id: 'mobile-pro', label: 'Mobile Pro', deviceClass: 'cellphone', width: 390, height: 844, pixelRatio: 3 },
93
+ { id: 'laptop-compact', label: 'Compact Laptop', deviceClass: 'laptop', width: 1366, height: 768, pixelRatio: 1 },
94
+ { id: 'laptop-hidpi', label: 'HiDPI Laptop', deviceClass: 'laptop', width: 1440, height: 900, pixelRatio: 2 },
95
+ { id: 'desktop-fhd', label: 'Full HD Workstation', deviceClass: 'desktop', width: 1920, height: 1080, pixelRatio: 1 },
96
+ { id: 'desktop-qhd', label: 'QHD Studio Display', deviceClass: 'desktop', width: 2560, height: 1440, pixelRatio: 2 },
97
+ ]);
98
+
99
+ /** The default preset used for each class in the Quad-Device Matrix. */
100
+ export const CLASS_DEFAULT_PRESET: Readonly<Record<DeviceClassId, string>> = Object.freeze({
101
+ wearable: 'watch-compact',
102
+ cellphone: 'mobile-standard',
103
+ laptop: 'laptop-hidpi',
104
+ desktop: 'desktop-fhd',
105
+ });
106
+
107
+ export function getPreset(id: string): DevicePreset | undefined {
108
+ return DEVICE_PRESETS.find((p) => p.id === id);
109
+ }
110
+
111
+ export function presetsForClass(deviceClass: DeviceClassId): readonly DevicePreset[] {
112
+ return DEVICE_PRESETS.filter((p) => p.deviceClass === deviceClass);
113
+ }
114
+
115
+ const gcd = (a: number, b: number): number => (b === 0 ? a : gcd(b, a % b));
116
+
117
+ /**
118
+ * INV-RVP-03: the aspect ratio of (w, h) is *derived*, never hand-written, so a
119
+ * label can never drift from the geometry it describes. Readable reduced
120
+ * fractions are preferred (`1920x1080 -> 16:9`); otherwise the ratio is
121
+ * normalised to the larger side (`820x1180 -> 1.44:1`).
122
+ */
123
+ export function aspectRatio(w: number, h: number): string {
124
+ if (!Number.isFinite(w) || !Number.isFinite(h) || w <= 0 || h <= 0) return '—';
125
+ const g = gcd(Math.round(w), Math.round(h));
126
+ const a = Math.round(w) / g;
127
+ const b = Math.round(h) / g;
128
+ if (a <= 40 && b <= 40) return `${a}:${b}`;
129
+ return `${(Math.max(w, h) / Math.min(w, h)).toFixed(2)}:1`;
130
+ }
131
+
132
+ /** INV-RVP-03: validate a dimension pair before it reaches a stage. */
133
+ export function validateDimensions(width: number, height: number): { valid: boolean; errors: string[] } {
134
+ const errors: string[] = [];
135
+ for (const [axis, v] of [['width', width], ['height', height]] as const) {
136
+ if (typeof v !== 'number' || !Number.isFinite(v) || !Number.isInteger(v)) errors.push(`${axis} must be an integer`);
137
+ else if (v < DIM_MIN) errors.push(`${axis} must be at least ${DIM_MIN}`);
138
+ else if (v > DIM_MAX) errors.push(`${axis} must be at most ${DIM_MAX}`);
139
+ }
140
+ return { valid: errors.length === 0, errors };
141
+ }
142
+
143
+ /**
144
+ * INV-RVP-02: the containment scale factor. A simulated device is scaled down to
145
+ * fit the available stage but is never scaled up (s <= 1), so no frame is ever
146
+ * clipped and no frame is ever blurred by upscaling.
147
+ */
148
+ export function containmentScale(
149
+ availableWidth: number,
150
+ availableHeight: number,
151
+ deviceWidth: number,
152
+ deviceHeight: number,
153
+ ): number {
154
+ if (!(availableWidth > 0) || !(availableHeight > 0) || !(deviceWidth > 0) || !(deviceHeight > 0)) return 1;
155
+ return Math.min(1, availableWidth / deviceWidth, availableHeight / deviceHeight);
156
+ }
157
+
158
+ /** 90° portrait <-> landscape swap: the dimensions physically exchange. */
159
+ export function rotate(preset: Pick<DevicePreset, 'width' | 'height'>): { width: number; height: number } {
160
+ return { width: preset.height, height: preset.width };
161
+ }
162
+
163
+ /**
164
+ * The auditing surface lives in `viewportAudit.ts` (it needs the kernel's hash
165
+ * for witness sealing) and is re-exported here so the registry remains the one
166
+ * import a caller needs for the responsive viewport model.
167
+ */
168
+ export {
169
+ auditViewport,
170
+ isMatrixConformant,
171
+ sealViewportWitness,
172
+ VIEWPORT_WITNESS_CONTRACT,
173
+ type MatrixAudit,
174
+ type ViewportMeasurement,
175
+ type ViewportViolation,
176
+ type ViewportWitness,
177
+ } from './viewportAudit.js';
@@ -0,0 +1,150 @@
1
+ /**
2
+ * viewportAudit.ts — Viewport Measurement Audit & Multi-Viewport Witness Sealing
3
+ * Canonical Path: src/core/viewport/viewportAudit.ts
4
+ * Program: EPIC-SMR · Sprint: SMR-12 (DoD-SMR-12-05, 12-06) · Invariant: INV-SMR-06
5
+ *
6
+ * The auditing half of the responsive viewport model: it judges one rendered
7
+ * measurement against one device class, and seals the conformance witness only
8
+ * when every class in the matrix passes. It is separated from
9
+ * `deviceArchetypeRegistry.ts` so both stay inside the Contract D ceiling, and
10
+ * the registry re-exports this surface so the named API is unchanged.
11
+ *
12
+ * Pure: no DOM, no storage, no network. Contract D budget: <= 200 LOC.
13
+ */
14
+
15
+ import { ContentHash } from 'clm-kernel';
16
+
17
+ import {
18
+ DEVICE_CLASS_IDS,
19
+ DEVICE_CLASSES,
20
+ DIM_MAX,
21
+ validateDimensions,
22
+ type DeviceClassId,
23
+ } from './deviceArchetypeRegistry.js';
24
+
25
+ export interface ViewportMeasurement {
26
+ /** Document scroll width in CSS px. */
27
+ readonly scrollWidth: number;
28
+ /** Visible client width in CSS px. */
29
+ readonly clientWidth: number;
30
+ /** Rendered payload size in bytes. */
31
+ readonly payloadBytes: number;
32
+ /** Sizes of interactive controls found in the frame, in CSS px. */
33
+ readonly touchTargets?: readonly number[];
34
+ }
35
+
36
+ export interface ViewportViolation {
37
+ readonly rule: 'overflow' | 'touch-target' | 'byte-budget' | 'dimensions';
38
+ readonly deviceClass: DeviceClassId;
39
+ readonly detail: string;
40
+ readonly measured: number;
41
+ readonly limit: number;
42
+ }
43
+
44
+ /**
45
+ * INV-SMR-06: audit one measurement against one device class. Returns every
46
+ * violation found, in a stable order, and never throws — a malformed
47
+ * measurement or an unknown class fails closed as a violation rather than
48
+ * passing by default.
49
+ */
50
+ export function auditViewport(
51
+ measurement: ViewportMeasurement,
52
+ deviceClass: DeviceClassId,
53
+ dimensions?: { width: number; height: number },
54
+ ): readonly ViewportViolation[] {
55
+ const spec = DEVICE_CLASSES[deviceClass];
56
+ if (!spec) {
57
+ return [{ rule: 'dimensions', deviceClass, detail: 'unknown device class', measured: 0, limit: 0 }];
58
+ }
59
+ const violations: ViewportViolation[] = [];
60
+
61
+ if (dimensions) {
62
+ const { valid, errors } = validateDimensions(dimensions.width, dimensions.height);
63
+ if (!valid) {
64
+ violations.push({
65
+ rule: 'dimensions',
66
+ deviceClass,
67
+ detail: errors.join('; '),
68
+ measured: dimensions.width,
69
+ limit: DIM_MAX,
70
+ });
71
+ }
72
+ }
73
+
74
+ const overflow = measurement.scrollWidth - measurement.clientWidth;
75
+ if (overflow > spec.maxHorizontalOverflow) {
76
+ violations.push({
77
+ rule: 'overflow',
78
+ deviceClass,
79
+ detail: `horizontal overflow ${overflow}px (scrollWidth ${measurement.scrollWidth} > clientWidth ${measurement.clientWidth})`,
80
+ measured: overflow,
81
+ limit: spec.maxHorizontalOverflow,
82
+ });
83
+ }
84
+
85
+ if (measurement.payloadBytes > spec.maxBytes) {
86
+ violations.push({
87
+ rule: 'byte-budget',
88
+ deviceClass,
89
+ detail: `payload ${measurement.payloadBytes} bytes exceeds the ${spec.label} budget`,
90
+ measured: measurement.payloadBytes,
91
+ limit: spec.maxBytes,
92
+ });
93
+ }
94
+
95
+ if (spec.minTouchTarget !== null) {
96
+ for (const size of measurement.touchTargets ?? []) {
97
+ if (size < spec.minTouchTarget) {
98
+ violations.push({
99
+ rule: 'touch-target',
100
+ deviceClass,
101
+ detail: `${size}px control is below the ${spec.minTouchTarget}px ${spec.label} minimum`,
102
+ measured: size,
103
+ limit: spec.minTouchTarget,
104
+ });
105
+ }
106
+ }
107
+ }
108
+
109
+ return violations;
110
+ }
111
+
112
+ export type MatrixAudit = Readonly<Record<DeviceClassId, readonly ViewportViolation[]>>;
113
+
114
+ /** True when every device class in the matrix passes its audit. */
115
+ export function isMatrixConformant(results: MatrixAudit): boolean {
116
+ return DEVICE_CLASS_IDS.every((id) => (results[id] ?? []).length === 0);
117
+ }
118
+
119
+ export const VIEWPORT_WITNESS_CONTRACT = 'urn:vcard:contract:landing_viewport_witness';
120
+
121
+ export interface ViewportWitness {
122
+ readonly contract: typeof VIEWPORT_WITNESS_CONTRACT;
123
+ readonly target: string;
124
+ readonly classes: readonly DeviceClassId[];
125
+ readonly verifiedAt: string;
126
+ readonly witnessHash: string;
127
+ }
128
+
129
+ /**
130
+ * Mint the Multi-Viewport Conformance VCard Witness. It is only minted when the
131
+ * whole matrix passes — a single violation returns null, so an unconformant
132
+ * page can never carry a witness (DoD-SMR-12-06). The hash covers the target,
133
+ * the classes, and the verdict, so the witness is content-addressed.
134
+ */
135
+ export function sealViewportWitness(
136
+ target: string,
137
+ results: MatrixAudit,
138
+ verifiedAt = '2026-10-18T00:00:00.000Z',
139
+ ): ViewportWitness | null {
140
+ if (!isMatrixConformant(results)) return null;
141
+ const classes = [...DEVICE_CLASS_IDS];
142
+ const verdict = `${target}|${classes.join(',')}|conformant`;
143
+ return {
144
+ contract: VIEWPORT_WITNESS_CONTRACT,
145
+ target,
146
+ classes,
147
+ verifiedAt,
148
+ witnessHash: ContentHash.computeString(verdict).asHex(),
149
+ };
150
+ }
@@ -0,0 +1,4 @@
1
+ export declare const STORE_EXTENSIONS: readonly ["-wal", "-shm", "-journal"];
2
+ export declare const STORE_FILENAMES: ReadonlySet<string>;
3
+ export declare function isStoreFile(filepathOrFilename: string): boolean;
4
+ export declare function filterStoreFiles(filepaths: readonly string[]): string[];
@@ -0,0 +1,54 @@
1
+ /**
2
+ * src/edge/storeFilter.js
3
+ *
4
+ * Store-file exclusion filter for disk watchers and ingestion (INV-CAS-12, DoD-08-2).
5
+ * Writes to *-wal, *-shm, *-journal and PATHS.stores produce NO transition and NO notification.
6
+ */
7
+
8
+ import path from 'path';
9
+ import { PATHS } from '../config/pathsConfig.js';
10
+
11
+ export const STORE_EXTENSIONS = ['-wal', '-shm', '-journal'];
12
+
13
+ export const STORE_FILENAMES = new Set(
14
+ Object.values(PATHS.stores || {})
15
+ );
16
+
17
+ /**
18
+ * Checks whether a given relative or absolute file path corresponds to an internal
19
+ * storage file (database file, WAL, SHM, or rollback journal).
20
+ *
21
+ * @param {string} filepathOrFilename - Path or filename to check
22
+ * @returns {boolean} true if the file should be excluded from watchers and transitions
23
+ */
24
+ export function isStoreFile(filepathOrFilename) {
25
+ if (!filepathOrFilename || typeof filepathOrFilename !== 'string') {
26
+ return false;
27
+ }
28
+
29
+ const base = path.basename(filepathOrFilename);
30
+
31
+ // Check store extensions
32
+ for (const ext of STORE_EXTENSIONS) {
33
+ if (base.endsWith(ext)) {
34
+ return true;
35
+ }
36
+ }
37
+
38
+ // Check designated store filenames
39
+ if (STORE_FILENAMES.has(base)) {
40
+ return true;
41
+ }
42
+
43
+ return false;
44
+ }
45
+
46
+ /**
47
+ * Filter an array of filepaths, discarding all internal store files.
48
+ *
49
+ * @param {string[]} filepaths
50
+ * @returns {string[]}
51
+ */
52
+ export function filterStoreFiles(filepaths) {
53
+ return filepaths.filter((fp) => !isStoreFile(fp));
54
+ }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * src/edge/storeFilter.ts
3
+ *
4
+ * Store-file exclusion filter for disk watchers and ingestion (INV-CAS-12, DoD-08-2).
5
+ * Writes to *-wal, *-shm, *-journal and PATHS.stores produce NO transition and NO notification.
6
+ * Contract D budget: <= 250 LOC.
7
+ */
8
+
9
+ import path from 'path';
10
+ import { PATHS } from '../config/pathsConfig.js';
11
+
12
+ export const STORE_EXTENSIONS = ['-wal', '-shm', '-journal'] as const;
13
+
14
+ export const STORE_FILENAMES: ReadonlySet<string> = new Set(
15
+ Object.values(PATHS.stores || {})
16
+ );
17
+
18
+ /**
19
+ * Checks whether a given relative or absolute file path corresponds to an internal
20
+ * storage file (database file, WAL, SHM, or rollback journal).
21
+ *
22
+ * @param filepathOrFilename - Path or filename to check
23
+ * @returns true if the file should be excluded from watchers and transitions
24
+ */
25
+ export function isStoreFile(filepathOrFilename: string): boolean {
26
+ if (!filepathOrFilename || typeof filepathOrFilename !== 'string') {
27
+ return false;
28
+ }
29
+
30
+ const base = path.basename(filepathOrFilename);
31
+
32
+ // Check store extensions
33
+ for (const ext of STORE_EXTENSIONS) {
34
+ if (base.endsWith(ext)) {
35
+ return true;
36
+ }
37
+ }
38
+
39
+ // Check designated store filenames
40
+ if (STORE_FILENAMES.has(base)) {
41
+ return true;
42
+ }
43
+
44
+ return false;
45
+ }
46
+
47
+ /**
48
+ * Filter an array of filepaths, discarding all internal store files.
49
+ */
50
+ export function filterStoreFiles(filepaths: readonly string[]): string[] {
51
+ return filepaths.filter((fp) => !isStoreFile(fp));
52
+ }
@@ -144,11 +144,87 @@ export function randomBytes(size) {
144
144
 
145
145
  export const webcrypto = typeof globalThis !== 'undefined' ? globalThis.crypto : undefined;
146
146
 
147
+ export function createPrivateKey(key) {
148
+ return { export: () => '', type: 'private', ...(typeof key === 'object' ? key : {}) };
149
+ }
150
+
151
+ export function createPublicKey(key) {
152
+ return { export: () => '', type: 'public', ...(typeof key === 'object' ? key : {}) };
153
+ }
154
+
155
+ export function diffieHellman() {
156
+ return {
157
+ computeSecret: () => new Uint8Array(32),
158
+ generateKeys: () => new Uint8Array(32),
159
+ };
160
+ }
161
+
162
+ export function generateKeyPairSync(type, options) {
163
+ return {
164
+ publicKey: createPublicKey({ type }),
165
+ privateKey: createPrivateKey({ type }),
166
+ };
167
+ }
168
+
169
+ export function sign(algorithm, data, key) {
170
+ return new Uint8Array(64);
171
+ }
172
+
173
+ export function verify(algorithm, data, key, signature) {
174
+ return false;
175
+ }
176
+
177
+ export function createCipheriv() {
178
+ return {
179
+ update: () => new Uint8Array(0),
180
+ final: () => new Uint8Array(0),
181
+ setAAD: () => {},
182
+ getAuthTag: () => new Uint8Array(16),
183
+ };
184
+ }
185
+
186
+ export function createDecipheriv() {
187
+ return {
188
+ update: () => new Uint8Array(0),
189
+ final: () => new Uint8Array(0),
190
+ setAAD: () => {},
191
+ setAuthTag: () => {},
192
+ };
193
+ }
194
+
195
+ export function hkdfSync(digest, ikm, salt, info, keylen) {
196
+ return new Uint8Array(keylen || 32);
197
+ }
198
+
199
+ export function randomFillSync(buffer, offset = 0, size) {
200
+ const len = size !== undefined ? size : buffer.length - offset;
201
+ const view = new Uint8Array(buffer.buffer, buffer.byteOffset + offset, len);
202
+ getRandomValues(view);
203
+ return buffer;
204
+ }
205
+
206
+ export class KeyObject {
207
+ constructor(type) {
208
+ this.type = type || 'secret';
209
+ }
210
+ }
211
+
147
212
  const cryptoPolyfill = {
213
+ createCipheriv,
214
+ createDecipheriv,
148
215
  createHash,
149
- randomUUID,
216
+ createPrivateKey,
217
+ createPublicKey,
218
+ diffieHellman,
219
+ generateKeyPairSync,
150
220
  getRandomValues,
221
+ hkdfSync,
222
+ KeyObject,
151
223
  randomBytes,
224
+ randomFillSync,
225
+ randomUUID,
226
+ sign,
227
+ verify,
152
228
  webcrypto,
153
229
  };
154
230
 
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Browser-safe isomorphic fs polyfill for Vite & Rollup client bundles.
3
+ */
4
+
5
+ export function existsSync() { return false; }
6
+ export function exists(path, cb) { if (cb) cb(false); }
7
+ export function readFileSync() { return ''; }
8
+ export function readFile(path, opt, cb) { const fn = typeof opt === 'function' ? opt : cb; if (fn) fn(null, ''); }
9
+ export function writeFileSync() {}
10
+ export function writeFile(path, data, opt, cb) { const fn = typeof opt === 'function' ? opt : cb; if (fn) fn(null); }
11
+ export function mkdirSync() {}
12
+ export function mkdir(path, opt, cb) { const fn = typeof opt === 'function' ? opt : cb; if (fn) fn(null); }
13
+ export function statSync() { return { isDirectory: () => false, isFile: () => false, size: 0, mtime: new Date() }; }
14
+ export function stat(path, cb) { if (cb) cb(null, { isDirectory: () => false, isFile: () => false, size: 0, mtime: new Date() }); }
15
+ export function readdirSync() { return []; }
16
+ export function readdir(path, cb) { if (cb) cb(null, []); }
17
+ export function unlinkSync() {}
18
+ export function unlink(path, cb) { if (cb) cb(null); }
19
+ export function rmSync() {}
20
+ export function rm(path, opt, cb) { const fn = typeof opt === 'function' ? opt : cb; if (fn) fn(null); }
21
+ export function mkdtempSync(prefix = '') { return prefix ? `${prefix}_tmp` : '/tmp'; }
22
+ export function mkdtemp(prefix, opt, cb) { const fn = typeof opt === 'function' ? opt : cb; const res = prefix ? `${prefix}_tmp` : '/tmp'; if (fn) fn(null, res); }
23
+
24
+ export const promises = {
25
+ readFile: async () => '',
26
+ writeFile: async () => {},
27
+ stat: async () => ({ isDirectory: () => false, isFile: () => false, size: 0, mtime: new Date() }),
28
+ readdir: async () => [],
29
+ mkdir: async () => {},
30
+ unlink: async () => {},
31
+ rm: async () => {},
32
+ mkdtemp: async (prefix = '') => (prefix ? `${prefix}_tmp` : '/tmp'),
33
+ };
34
+
35
+ export const constants = {
36
+ F_OK: 0,
37
+ R_OK: 4,
38
+ W_OK: 2,
39
+ X_OK: 1,
40
+ };
41
+
42
+ const fsPolyfill = {
43
+ existsSync,
44
+ exists,
45
+ readFileSync,
46
+ readFile,
47
+ writeFileSync,
48
+ writeFile,
49
+ mkdirSync,
50
+ mkdir,
51
+ statSync,
52
+ stat,
53
+ readdirSync,
54
+ readdir,
55
+ unlinkSync,
56
+ unlink,
57
+ rmSync,
58
+ rm,
59
+ mkdtempSync,
60
+ mkdtemp,
61
+ promises,
62
+ constants,
63
+ };
64
+
65
+ export default fsPolyfill;