mcard-studio 0.0.1 → 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 (212) hide show
  1. package/README.md +3 -0
  2. package/astro.config.mjs +46 -2
  3. package/bin/mcard-studio.mjs +1 -1
  4. package/cli/lib/runtimeContext.mjs +6 -3
  5. package/dist/client/_astro/{ChartAnalyticsViewlet.Cevj0EOs.js → ChartAnalyticsViewlet.CBW-JyA3.js} +1 -1
  6. package/dist/client/_astro/ClmPcardViewlet.cvKsR2ng.js +3 -0
  7. package/dist/client/_astro/D3GraphViewlet.8YEIrCGL.js +2 -0
  8. package/dist/client/_astro/DockviewSpatialWorkbench.BTd66LPl.js +12 -0
  9. package/dist/client/_astro/DocumentViewlets.KY1HcNka.js +2 -0
  10. package/dist/client/_astro/DxfViewlet.B3N5zpZR.js +1 -0
  11. package/dist/client/_astro/ExcalidrawWhiteboardViewlet.CMJGCQN4.js +1 -0
  12. package/dist/client/_astro/{FaroVCardSpanInstrumenter.BIk2NhJY.js → FaroVCardSpanInstrumenter.ClIqZujq.js} +1 -1
  13. package/dist/client/_astro/{FontSpecimenViewlet.CpONhJh0.js → FontSpecimenViewlet.ChIyr0B8.js} +1 -1
  14. package/dist/client/_astro/HeadMeta.astro_astro_type_script_index_0_lang.D3FSc061.js +1 -0
  15. package/dist/client/_astro/{ImageViewlet.CHeNvX6L.js → ImageViewlet.Cs-u7-wt.js} +1 -1
  16. package/dist/client/_astro/{KatexFormulaViewlet.Cy_InWOK.js → KatexFormulaViewlet.0nOzV_qD.js} +1 -1
  17. package/dist/client/_astro/KoishiChatViewlet.DLsMmwdb.js +16 -0
  18. package/dist/client/_astro/MCardLibraryHarness.WBT9W10S.js +2 -0
  19. package/dist/client/_astro/{MarkdownViewlet.qoPlM-TZ.js → MarkdownViewlet.BIolkNXf.js} +25 -25
  20. package/dist/client/_astro/{MermaidDiagramViewlet.RnwDfQl6.js → MermaidDiagramViewlet.CkRk7QsS.js} +1 -1
  21. package/dist/client/_astro/PCardRendererBridge.DhaRSprd.js +1 -0
  22. package/dist/client/_astro/RendererPCardRegistry.brM2KiQs.js +1 -0
  23. package/dist/client/_astro/{SchemaYamlViewlet.D6HVdmrq.js → SchemaYamlViewlet.Bc7nkK4M.js} +1 -1
  24. package/dist/client/_astro/{ShellContainer.astro_astro_type_script_index_0_lang.2oi8fhQo.js → ShellContainer.astro_astro_type_script_index_0_lang.5q1gCLvf.js} +1 -1
  25. package/dist/client/_astro/{Spatial3dViewlet.CCYBSSib.js → Spatial3dViewlet.C-jjhr0A.js} +1 -1
  26. package/dist/client/_astro/{StudioLayout.CBgiVbeb.css → StudioLayout.CX8XGtZV.css} +1 -1
  27. package/dist/client/_astro/StudioWorkbench.B1QwGHWM.js +7 -0
  28. package/dist/client/_astro/{SvgViewlet.BxlWQ-JX.js → SvgViewlet.uGxvb06H.js} +1 -1
  29. package/dist/client/_astro/{TerminalView.DWZR-hUa.js → TerminalView.DP7G7E1m.js} +4 -4
  30. package/dist/client/_astro/{ThemeSettingsViewlet.Cb1r8fWw.js → ThemeSettingsViewlet.UaTHcGnF.js} +1 -1
  31. package/dist/client/_astro/{TikzDiagramViewlet.CqY7VTeP.js → TikzDiagramViewlet.O8MJyXfT.js} +1 -1
  32. package/dist/client/_astro/VideoPlayerViewlet.-ycmo3kY.js +1 -0
  33. package/dist/client/_astro/WebappZenViewlet.PNce4u2T.js +1 -0
  34. package/dist/client/_astro/{WelcomeViewport.LwKTA6h7.js → WelcomeViewport.CZ6RxGSw.js} +1 -1
  35. package/dist/client/_astro/{agentIdentityCredentialService.BtKVsl2C.js → agentIdentityCredentialService.BEtZzBlO.js} +5 -5
  36. package/dist/client/_astro/cardTypeDetector.C2HH5RnU.js +1 -0
  37. package/dist/client/_astro/disposable.BmlxZrDf.js +1 -0
  38. package/dist/client/_astro/{markdownService.D-tM2RYx.js → markdownService.CpuKl0vp.js} +1 -1
  39. package/dist/client/_astro/{mcardStore.BiAvqM-D.js → mcardStore.nSWnzeLg.js} +2 -2
  40. package/dist/client/_astro/mcardVfs.BSdys1Y7.js +3 -0
  41. package/dist/client/_astro/pathsConfig.CSBBSzwH.js +2 -0
  42. package/dist/client/_astro/polyfills.Bi7kO8cu.js +1 -0
  43. package/dist/client/_astro/rendererEventBus.DirFDmGw.js +1 -0
  44. package/dist/client/_astro/themeStore.BajxvCga.js +1 -0
  45. package/dist/client/_astro/{tikzCompiler.DFojjdxR.js → tikzCompiler.-fXMNQpz.js} +1 -1
  46. package/dist/client/_astro/{useMCardHydration.Co47OH3D.js → useMCardHydration.Bjj_N5Gv.js} +1 -1
  47. package/dist/client/_astro/vendor-ai.D6NcJ6lu.js +69 -0
  48. package/dist/client/_astro/vendor-clm-kernel.B0kxq3g4.js +108 -0
  49. package/dist/client/_astro/vfsHandles.D4Pq18pW.js +1 -0
  50. package/dist/client/_astro/vfsPersistence.DVrd1BZj.js +1 -0
  51. package/dist/client/_astro/vfsTransactions.DBNtFuRz.js +1 -0
  52. package/dist/client/_astro/{workspaceStore.CXakha4Y.js → workspaceStore.DUHW2YBc.js} +1 -1
  53. package/dist/client/js/buffer-polyfill.js +14 -0
  54. package/dist/server/chunks/{StudioLayout_D163irJ0.mjs → StudioLayout_taayQJ5b.mjs} +2 -2
  55. package/dist/server/chunks/{_.._ZXsz792-.mjs → _.._CoQKwo62.mjs} +137 -91
  56. package/dist/server/chunks/{_handle__D_cIJYrU.mjs → _handle__D8dKQPUS.mjs} +3 -3
  57. package/dist/server/chunks/{cardTypeDetector_CyW1Xnmy.mjs → cardTypeDetector_C55M_HWS.mjs} +9 -0
  58. package/dist/server/chunks/{cards_B89BvF6W.mjs → cards_rVOc8K6H.mjs} +2 -2
  59. package/dist/server/chunks/cas_DTxlZ4Le.mjs +68 -0
  60. package/dist/server/chunks/{dispatch_DOwSKukU.mjs → dispatch_BTW4E_BJ.mjs} +8 -7
  61. package/dist/server/chunks/{dispatch_CxWKiHpn.mjs → dispatch_MbkljUxD.mjs} +8 -8
  62. package/dist/server/chunks/{export_DRouradA.mjs → export_DkEwDE2T.mjs} +3 -3
  63. package/dist/server/chunks/{health_Dfa5I0-X.mjs → health_cRt0M0yu.mjs} +1 -1
  64. package/dist/server/chunks/{mcard-library_DvPPUs9_.mjs → mcard-library_CLHvyslV.mjs} +1 -1
  65. package/dist/server/chunks/{mcardVfs_CeezzRvt.mjs → mcardVfs_DvNburKb.mjs} +5 -30
  66. package/dist/server/chunks/{move__RFvIDkq.mjs → move_DYcaXBLV.mjs} +6 -6
  67. package/dist/server/chunks/{pathsConfig_CgNYYLVm.mjs → pathsConfig_Dack-p2f.mjs} +13 -3
  68. package/dist/server/chunks/{proxy_CrWJQIBe.mjs → proxy_CMbbdBPW.mjs} +2 -2
  69. package/dist/server/chunks/{raw_DzNDaDVP.mjs → raw_C97sJWhg.mjs} +59 -26
  70. package/dist/server/chunks/{serverBootstrap_XKo2s6Ha.mjs → serverBootstrap_BDdSRIu5.mjs} +2 -2
  71. package/dist/server/chunks/tree_BwmO-pTe.mjs +186 -0
  72. package/dist/server/chunks/vfsCore_DIKpk-pk.mjs +98 -0
  73. package/dist/server/chunks/{vfsTreeScan_CKp7kMt9.mjs → vfsTreeScan_CRoCluPB.mjs} +18 -10
  74. package/dist/server/chunks/workspaceRoot_CRx3taID.mjs +157 -0
  75. package/dist/server/chunks/{write_popiFsO7.mjs → write_BLsmsTIx.mjs} +6 -5
  76. package/dist/server/chunks/{ws-server-init_CkcgcI5V.mjs → ws-server-init_Cfft7U5u.mjs} +343 -298
  77. package/dist/server/entry.mjs +8 -4
  78. package/dist/server/entry2.mjs +67 -28
  79. package/dist/server/virtual_astro_middleware.mjs +2 -2
  80. package/package.json +2 -2
  81. package/public/js/buffer-polyfill.js +14 -0
  82. package/src/components/studio/views/cardViewlets/ClmRegistryComponentViewlet.tsx +133 -0
  83. package/src/components/studio/views/cardViewlets/DxfViewlet.tsx +230 -0
  84. package/src/components/studio/views/cardViewlets/VideoPlayerViewlet.tsx +4 -4
  85. package/src/components/studio/views/cardViewlets/coreViewletDefs.ts +2 -2
  86. package/src/components/studio/views/cardViewlets/documents/AudioPlayerViewlet.tsx +15 -3
  87. package/src/components/studio/views/cardViewlets/documents/PdfViewlet.tsx +25 -7
  88. package/src/components/studio/views/cardViewlets/markdown/stages/wikilinkStage.ts +2 -1
  89. package/src/components/studio/views/cardViewlets/mediaViewletDefs.ts +21 -1
  90. package/src/components/studio/views/cardViewlets/webapp/WebappCanvas.tsx +40 -15
  91. package/src/components/studio/views/cardViewlets/webapp/WebappDevicePresetBar.tsx +108 -0
  92. package/src/components/studio/views/cardViewlets/webapp/WebappZenViewlet.tsx +23 -30
  93. package/src/components/studio/views/fileTree/MCardFileTree.tsx +71 -54
  94. package/src/components/studio/views/fileTree/hooks/useFileTreeSync.ts +0 -1
  95. package/src/components/studio/views/fileTree/hooks/usePartitionedTrees.ts +68 -23
  96. package/src/components/studio/views/fileTree/hooks/useSectionAccordion.ts +21 -11
  97. package/src/components/studio/views/functions/UnifiedFunctionExplorerViewlet.tsx +168 -0
  98. package/src/components/studio/views/history/HistoryPanel.tsx +110 -0
  99. package/src/components/studio/views/lineage/LineagePanel.tsx +152 -0
  100. package/src/components/studio/views/navigation/HandleLineageDrawer.tsx +89 -0
  101. package/src/components/studio/views/navigation/MultiCardCollectionBrowser.tsx +154 -0
  102. package/src/components/studio/views/pills/HashPill.tsx +101 -0
  103. package/src/components/studio/views/residency/ResidencyIndicator.tsx +82 -0
  104. package/src/config/app_config.json +3 -3
  105. package/src/core/projection/catalog.ts +105 -0
  106. package/src/core/projection/collection.ts +148 -0
  107. package/src/core/projection/handleSubscription.ts +132 -0
  108. package/src/core/projection/index.ts +4 -0
  109. package/src/core/projection/selectors.ts +29 -0
  110. package/src/core/projection/views.ts +242 -0
  111. package/src/core/refinement/designMetrics.ts +104 -0
  112. package/src/core/refinement/fibrationProjector.ts +142 -0
  113. package/src/core/refinement/lagrangianEngine.ts +137 -0
  114. package/src/core/refinement/refinementCommands.ts +82 -0
  115. package/src/core/viewport/deviceArchetypeRegistry.ts +177 -0
  116. package/src/core/viewport/viewportAudit.ts +150 -0
  117. package/src/edge/storeFilter.d.ts +4 -0
  118. package/src/edge/storeFilter.js +54 -0
  119. package/src/edge/storeFilter.ts +52 -0
  120. package/src/layouts/StudioLayout.astro +1 -0
  121. package/src/lib/cryptoPolyfill.js +77 -1
  122. package/src/lib/fsPolyfill.js +65 -0
  123. package/src/lib/urlPolyfill.js +21 -0
  124. package/src/lib/zlibPolyfill.js +35 -0
  125. package/src/packages/mcard-studio/package.json +2 -2
  126. package/src/packages/mcard-studio/type/legacyMapping.ts +5 -0
  127. package/src/packages/mcard-studio/viewlets/manifests.ts +2 -0
  128. package/src/packages/mcard-studio/viewlets/moduleMap.ts +12 -0
  129. package/src/packages/mcard-studio/viewlets/refinementManifests.ts +114 -0
  130. package/src/pages/api/dispatch.ts +3 -2
  131. package/src/pages/api/vfs/cas.ts +114 -0
  132. package/src/pages/api/vfs/move.ts +5 -5
  133. package/src/pages/api/vfs/raw.ts +72 -27
  134. package/src/pages/api/vfs/tree.ts +130 -11
  135. package/src/pages/api/vfs/write.ts +5 -4
  136. package/src/pages/index.astro +75 -0
  137. package/src/server/api/kernelDispatch.ts +8 -8
  138. package/src/server/artifactCollectionService.ts +4 -7
  139. package/src/server/artifactRepository.ts +4 -3
  140. package/src/server/clmRunner.mjs +1 -1
  141. package/src/server/collectionOwner.mjs +5 -5
  142. package/src/server/effects/executionPersistenceService.mjs +11 -11
  143. package/src/server/effects/resultSealingService.mjs +2 -2
  144. package/src/server/fileIngestService.mjs +21 -9
  145. package/src/server/fileWatcherService.mjs +4 -1
  146. package/src/server/handlers/fileChangeHandler.mjs +18 -10
  147. package/src/server/handlers/saveExecutionLogHandler.mjs +6 -6
  148. package/src/server/notificationService.mjs +14 -1
  149. package/src/server/scripts/buildSeedingMemory.mjs +3 -3
  150. package/src/server/serverMemoryRepository.ts +41 -59
  151. package/src/server/vfsTreeScan.ts +16 -10
  152. package/src/server/workspaceRoot.ts +143 -5
  153. package/src/services/cardTypeDetector.ts +4 -0
  154. package/src/services/databaseSyncService.ts +30 -46
  155. package/src/services/inBrowserLlm/engines/litertEngine.ts +1 -1
  156. package/src/services/namespaceProtocolClient.ts +221 -0
  157. package/src/services/renderers/pcard/RendererPCardRegistry.ts +4 -66
  158. package/src/services/renderers/pcard/modalitySpecs.ts +125 -0
  159. package/src/services/renderers/pcard/types.ts +7 -1
  160. package/src/services/renderers/rendererEventBus.ts +5 -3
  161. package/src/services/unifiedFunctionExecutionService.ts +145 -0
  162. package/src/services/vfs/vfsCore.ts +12 -1
  163. package/src/services/vfs/vfsMigration.ts +95 -0
  164. package/src/services/vfs/vfsMutations.ts +17 -35
  165. package/src/services/vfs/vfsPersistence.ts +19 -24
  166. package/src/services/vfs/vfsSync.ts +55 -17
  167. package/src/services/vfs/vfsVersions.ts +23 -34
  168. package/src/services/workbenchExecutionPolicy.ts +183 -0
  169. package/src/stores/mcardCollectionStore.ts +2 -0
  170. package/src/styles/dockview.css +34 -0
  171. package/src/ui/viewlets/FibrationRefinementViewlet.tsx +155 -0
  172. package/src/ui/viewlets/PetriConformanceViewlet.tsx +166 -0
  173. package/src/ui/viewlets/ResponsiveViewportLabViewlet.tsx +175 -0
  174. package/src/ui/viewlets/SprintGovernanceViewlet.tsx +176 -0
  175. package/src/ui/viewlets/viewletFocus.ts +35 -0
  176. package/src/ui/viewlets/viewportLabParts.tsx +190 -0
  177. package/dist/client/_astro/ClmPcardViewlet.DW5Yft0E.js +0 -3
  178. package/dist/client/_astro/D3GraphViewlet.DAjPz1DP.js +0 -2
  179. package/dist/client/_astro/DockviewSpatialWorkbench.DyQjSoHd.js +0 -12
  180. package/dist/client/_astro/DocumentViewlets.Dm_GL3AL.js +0 -2
  181. package/dist/client/_astro/ExcalidrawWhiteboardViewlet.DrlW7B6G.js +0 -1
  182. package/dist/client/_astro/HeadMeta.astro_astro_type_script_index_0_lang.DGXU-3Lu.js +0 -1
  183. package/dist/client/_astro/KoishiChatViewlet.B0eDEMnT.js +0 -16
  184. package/dist/client/_astro/MCardLibraryHarness.CUJLJFBt.js +0 -2
  185. package/dist/client/_astro/PCardRendererBridge.BnyaE05I.js +0 -1
  186. package/dist/client/_astro/RendererPCardRegistry.CLr4j1Ub.js +0 -1
  187. package/dist/client/_astro/StudioWorkbench.CF0SOYwy.js +0 -7
  188. package/dist/client/_astro/VideoPlayerViewlet.DoSYmmoQ.js +0 -1
  189. package/dist/client/_astro/WebappZenViewlet.CQW50OhX.js +0 -1
  190. package/dist/client/_astro/cardTypeDetector.C9kGObMh.js +0 -1
  191. package/dist/client/_astro/disposable.66apX1Q2.js +0 -1
  192. package/dist/client/_astro/empty.DOwCrGXH.js +0 -1
  193. package/dist/client/_astro/mcardVfs.Bj-RA0p7.js +0 -2
  194. package/dist/client/_astro/path.CR60mj9W.js +0 -1
  195. package/dist/client/_astro/pathsConfig.D0hV34p7.js +0 -2
  196. package/dist/client/_astro/polyfills.DcBkS56X.js +0 -1
  197. package/dist/client/_astro/rendererEventBus.CyFnSRLk.js +0 -1
  198. package/dist/client/_astro/themeStore.zUMFLo3Q.js +0 -1
  199. package/dist/client/_astro/vendor-ai.CZe7UVVK.js +0 -69
  200. package/dist/client/_astro/vfsHandles.B-nczBRy.js +0 -1
  201. package/dist/client/_astro/vfsPersistence.D6zRzVML.js +0 -1
  202. package/dist/client/_astro/vfsTransactions.04mkEHxD.js +0 -1
  203. package/dist/server/chunks/cryptoPolyfill_99rxUwYC.mjs +0 -180
  204. package/dist/server/chunks/kernelHash_DRaj51hY.mjs +0 -5
  205. package/dist/server/chunks/tree_CE2BhvyJ.mjs +0 -76
  206. package/dist/server/chunks/vfsCore_B6nCiBl5.mjs +0 -21
  207. package/dist/server/chunks/workspaceRoot_DVSUbYkd.mjs +0 -71
  208. package/src/server/kernelHash.ts +0 -22
  209. package/src/server/storage/cardCollection.ts +0 -94
  210. package/src/server/storage/index.ts +0 -3
  211. package/src/server/storage/mcard.ts +0 -99
  212. package/src/server/storage/sqliteNodeEngine.ts +0 -121
@@ -0,0 +1,145 @@
1
+ /**
2
+ * src/services/unifiedFunctionExecutionService.ts
3
+ * Unified Function Execution — read-only by default (SMR-10 · DoD-SMR-10-05).
4
+ *
5
+ * Discovery never implies authority. This service exposes *what execution would
6
+ * require* and refuses to execute until every requirement is satisfied by a real,
7
+ * verifiable gate. At the time of writing no such gate exists: `INV-NP-05` is
8
+ * "Staged Directory Publishing", not an authentication/CSRF/allowlist gate, so the
9
+ * requirement list below is honest about being unmet rather than aspirational.
10
+ *
11
+ * There is deliberately no execution endpoint in the route surface
12
+ * (`src/pages/api/clm/execute-fiber.ts` is NOT added): adding it before its gates
13
+ * exist would expose the raw kernel gateway.
14
+ *
15
+ * Contract D budget: <= 250 LOC.
16
+ */
17
+
18
+ export interface ExecutionRequirement {
19
+ readonly id: string;
20
+ readonly description: string;
21
+ readonly satisfied: boolean;
22
+ readonly evidence: string | null;
23
+ }
24
+
25
+ export interface ExecutionCapability {
26
+ readonly enabled: boolean;
27
+ readonly reason: string;
28
+ readonly allowlist: readonly string[];
29
+ readonly requirements: readonly ExecutionRequirement[];
30
+ }
31
+
32
+ export interface ExecutionRequest {
33
+ readonly handle: string;
34
+ readonly runtime?: string;
35
+ readonly payload?: unknown;
36
+ }
37
+
38
+ export class ExecutionDisabledError extends Error {
39
+ readonly code = 'EXECUTION_DISABLED';
40
+ constructor(reason: string) {
41
+ super(reason);
42
+ this.name = 'ExecutionDisabledError';
43
+ }
44
+ }
45
+
46
+ /**
47
+ * Requirements an execution endpoint must meet before it may be added to the route
48
+ * surface. Each is `satisfied: false` with a named missing artifact, so this list is
49
+ * a checklist rather than a claim.
50
+ */
51
+ export const EXECUTION_REQUIREMENTS: readonly ExecutionRequirement[] = [
52
+ {
53
+ id: 'authentication',
54
+ description: 'Caller identity is authenticated and bound to a DID',
55
+ satisfied: false,
56
+ evidence: null,
57
+ },
58
+ {
59
+ id: 'authorization',
60
+ description: 'The authenticated principal is authorized for the target handle',
61
+ satisfied: false,
62
+ evidence: null,
63
+ },
64
+ {
65
+ id: 'allowlist',
66
+ description: 'The handle appears in an explicit, reviewed execution allowlist',
67
+ satisfied: false,
68
+ evidence: null,
69
+ },
70
+ {
71
+ id: 'csrf-same-origin',
72
+ description: 'CSRF protection and same-origin enforcement are verified',
73
+ satisfied: false,
74
+ evidence: null,
75
+ },
76
+ {
77
+ id: 'sandbox-process-boundary',
78
+ description: 'Execution runs inside a sandbox with a verified process boundary',
79
+ satisfied: false,
80
+ evidence: null,
81
+ },
82
+ ];
83
+
84
+ export interface UnifiedFunctionExecutionOptions {
85
+ /** Endpoint path, if one is ever added. Absent today by design. */
86
+ readonly endpoint?: string;
87
+ /** Reviewed allowlist of executable handles. Empty until the gates above pass. */
88
+ readonly allowlist?: readonly string[];
89
+ }
90
+
91
+ export class UnifiedFunctionExecutionService {
92
+ private readonly endpoint?: string;
93
+ private readonly allowlist: readonly string[];
94
+
95
+ constructor(options: UnifiedFunctionExecutionOptions = {}) {
96
+ this.endpoint = options.endpoint;
97
+ this.allowlist = options.allowlist ?? [];
98
+ }
99
+
100
+ /** What execution would require, and whether it is currently permitted. */
101
+ get capability(): ExecutionCapability {
102
+ const unmet = EXECUTION_REQUIREMENTS.filter((requirement) => !requirement.satisfied);
103
+ const enabled = unmet.length === 0 && Boolean(this.endpoint) && this.allowlist.length > 0;
104
+ return {
105
+ enabled,
106
+ reason: enabled
107
+ ? 'All execution requirements are satisfied.'
108
+ : `Execution is disabled: ${unmet.length} requirement(s) unmet, ` +
109
+ `${this.endpoint ? 'endpoint configured' : 'no endpoint in the route surface'}, ` +
110
+ `${this.allowlist.length} allowlisted handle(s).`,
111
+ allowlist: [...this.allowlist],
112
+ requirements: EXECUTION_REQUIREMENTS,
113
+ };
114
+ }
115
+
116
+ /** True only when the capability is enabled and the handle is allowlisted. */
117
+ canExecute(handle: string): boolean {
118
+ return this.capability.enabled && this.allowlist.includes(handle);
119
+ }
120
+
121
+ /**
122
+ * Read-only discovery surface: everything a caller may inspect without authority.
123
+ */
124
+ describe(handle: string): {
125
+ readonly handle: string;
126
+ readonly executable: false;
127
+ readonly capability: ExecutionCapability;
128
+ } {
129
+ return { handle, executable: false, capability: this.capability };
130
+ }
131
+
132
+ /** Refuses. Execution has no satisfied gate, so there is nothing to call. */
133
+ async execute(request: ExecutionRequest): Promise<never> {
134
+ if (!this.canExecute(request.handle)) {
135
+ throw new ExecutionDisabledError(this.capability.reason);
136
+ }
137
+ // Unreachable until the requirements above are satisfied and verified.
138
+ throw new ExecutionDisabledError(
139
+ `Execution transport for "${request.handle}" is not implemented; ` +
140
+ 'the route surface intentionally omits the kernel gateway.',
141
+ );
142
+ }
143
+ }
144
+
145
+ export const unifiedFunctionExecutionService = new UnifiedFunctionExecutionService();
@@ -9,7 +9,13 @@
9
9
  * consume it via the mcardVfs facade re-export.
10
10
  */
11
11
 
12
- import { MCardFileSystem } from 'clm-kernel';
12
+ import { MCardFileSystem, registerIndexedDbPlugin } from 'clm-kernel';
13
+ import { migrateAndRetireLegacyIndexedDb } from './vfsMigration';
14
+
15
+ // Register kernel-owned browser driver before createOptimal (Sprint CAS-05 / DoD-05-3)
16
+ if (typeof window !== 'undefined') {
17
+ registerIndexedDbPlugin();
18
+ }
13
19
 
14
20
  /**
15
21
  * Universal Content-Addressable MCard Virtual Filesystem for Studio Workbench (INV-04, INV-05, INV-09).
@@ -18,3 +24,8 @@ import { MCardFileSystem } from 'clm-kernel';
18
24
  export const studioMCardFs = MCardFileSystem.createOptimal({
19
25
  dbPath: '.clm/content_memory.db',
20
26
  });
27
+
28
+ if (typeof window !== 'undefined') {
29
+ // Trigger one-time retirement migration
30
+ migrateAndRetireLegacyIndexedDb(studioMCardFs).catch(() => {});
31
+ }
@@ -0,0 +1,95 @@
1
+ /**
2
+ * VFS Migration — One-time retirement migration for legacy clm_workbench_db (DoD-05-3, D7, R7)
3
+ * Canonical Path: src/services/vfs/vfsMigration.ts
4
+ * NOTE: Migration file scheduled for deletion after replica retirement.
5
+ *
6
+ * Reads legacy clm_cas_blobs, clm_handle_registry, clm_handle_history and clm_sqlite_snapshots
7
+ * into kernel-owned CAS driver, then deletes clm_workbench_db.
8
+ */
9
+
10
+ import { ContentHash, AgentDid } from 'clm-kernel';
11
+
12
+ const DB_NAME = 'clm_workbench_db';
13
+ const DB_VERSION = 2;
14
+
15
+ export const STORE_CAS = 'clm_cas_blobs';
16
+ export const STORE_HANDLES = 'clm_handle_registry';
17
+ export const STORE_HISTORY = 'clm_handle_history';
18
+ export const STORE_SNAPSHOTS = 'clm_sqlite_snapshots';
19
+ export const STORE_LEGACY = 'clm_content_memory_db';
20
+
21
+ /**
22
+ * Migration-only IndexedDB opener.
23
+ * Scheduled for deletion once all client replicas migrate to kernel CAS driver.
24
+ */
25
+ export function openMigrationIndexedDb(): Promise<IDBDatabase> {
26
+ return new Promise((resolve, reject) => {
27
+ if (typeof window === 'undefined' || !window.indexedDB) {
28
+ return reject(new Error('IndexedDB not available'));
29
+ }
30
+ const req = window.indexedDB.open(DB_NAME, DB_VERSION);
31
+ req.onupgradeneeded = () => {
32
+ const db = req.result;
33
+ if (!db.objectStoreNames.contains(STORE_CAS)) db.createObjectStore(STORE_CAS, { keyPath: 'hash' });
34
+ if (!db.objectStoreNames.contains(STORE_HANDLES)) db.createObjectStore(STORE_HANDLES, { keyPath: 'handle' });
35
+ if (!db.objectStoreNames.contains(STORE_HISTORY)) db.createObjectStore(STORE_HISTORY, { keyPath: 'id', autoIncrement: true });
36
+ if (!db.objectStoreNames.contains(STORE_SNAPSHOTS)) db.createObjectStore(STORE_SNAPSHOTS, { keyPath: 'id' });
37
+ if (!db.objectStoreNames.contains(STORE_LEGACY)) db.createObjectStore(STORE_LEGACY);
38
+ };
39
+ req.onsuccess = () => resolve(req.result);
40
+ req.onerror = () => reject(req.error);
41
+ });
42
+ }
43
+
44
+ /**
45
+ * Executes one-time migration from legacy clm_workbench_db to kernel driver, then deletes database.
46
+ */
47
+ export async function migrateAndRetireLegacyIndexedDb(targetFs?: any): Promise<boolean> {
48
+ if (typeof window === 'undefined' || !window.indexedDB) return false;
49
+
50
+ try {
51
+ const db = await openMigrationIndexedDb();
52
+ const storeNames = Array.from(db.objectStoreNames);
53
+
54
+ if (storeNames.includes(STORE_CAS)) {
55
+ const tx = db.transaction([STORE_CAS], 'readonly');
56
+ const store = tx.objectStore(STORE_CAS);
57
+ const req = store.getAll();
58
+ await new Promise<void>((resolve) => {
59
+ req.onsuccess = () => {
60
+ const items = (req.result as any[]) || [];
61
+ for (const item of items) {
62
+ if (item.hash && item.content) {
63
+ try {
64
+ const ch = ContentHash.parse(item.hash);
65
+ const bytes = typeof item.content === 'string'
66
+ ? new TextEncoder().encode(item.content)
67
+ : (item.content instanceof Uint8Array ? item.content : new Uint8Array(item.content));
68
+ if (targetFs && typeof targetFs.writeFile === 'function') {
69
+ targetFs.writeFile(item.handle || item.hash, bytes);
70
+ }
71
+ } catch {}
72
+ }
73
+ }
74
+ resolve();
75
+ };
76
+ req.onerror = () => resolve();
77
+ });
78
+ }
79
+
80
+ db.close();
81
+
82
+ // Delete legacy replica database
83
+ await new Promise<void>((resolve, reject) => {
84
+ const delReq = window.indexedDB.deleteDatabase(DB_NAME);
85
+ delReq.onsuccess = () => resolve();
86
+ delReq.onerror = () => reject(delReq.error);
87
+ delReq.onblocked = () => resolve();
88
+ });
89
+
90
+ return true;
91
+ } catch (err) {
92
+ console.warn('[VFS Migration] Migration completed or database already retired:', err);
93
+ return false;
94
+ }
95
+ }
@@ -50,39 +50,19 @@ export function propagateHandleReferenceUpdate(
50
50
 
51
51
  // Deduplicate unique cards by handle
52
52
  const uniqueCardsMap = new Map<string, MCardFileNode>();
53
- for (const node of Object.values(tree)) {
54
- if (node && node.handle) {
55
- uniqueCardsMap.set(node.handle, node);
56
- }
57
- }
53
+ for (const node of Object.values(tree)) if (node?.handle) uniqueCardsMap.set(node.handle, node);
58
54
 
59
55
  const oldHandleRegex = new RegExp(escapeRegExp(oldHandle), 'g');
60
56
  const oldPathRegex = new RegExp(escapeRegExp(oldPath), 'g');
61
57
 
62
58
  for (const card of uniqueCardsMap.values()) {
63
- // Skip the subject card itself
64
- if (
65
- card.handle === oldHandle ||
66
- card.handle === newHandle ||
67
- card.path === oldPath ||
68
- card.path === newPath
69
- ) {
70
- continue;
71
- }
59
+ if (card.handle === oldHandle || card.handle === newHandle || card.path === oldPath || card.path === newPath) continue;
72
60
 
73
61
  if (typeof card.content === 'string') {
74
62
  let content = card.content;
75
63
  let hasUpdate = false;
76
-
77
- if (content.includes(oldHandle)) {
78
- content = content.replace(oldHandleRegex, newHandle);
79
- hasUpdate = true;
80
- }
81
- if (content.includes(oldPath)) {
82
- content = content.replace(oldPathRegex, newPath);
83
- hasUpdate = true;
84
- }
85
-
64
+ if (content.includes(oldHandle)) { content = content.replace(oldHandleRegex, newHandle); hasUpdate = true; }
65
+ if (content.includes(oldPath)) { content = content.replace(oldPathRegex, newPath); hasUpdate = true; }
86
66
  if (hasUpdate) {
87
67
  updateMCardContent(card.handle, content);
88
68
  updatedHandles.push(card.handle);
@@ -90,10 +70,7 @@ export function propagateHandleReferenceUpdate(
90
70
  }
91
71
  }
92
72
 
93
- return {
94
- referencingCardsUpdated: updatedHandles.length,
95
- updatedHandles,
96
- };
73
+ return { referencingCardsUpdated: updatedHandles.length, updatedHandles };
97
74
  }
98
75
 
99
76
  /**
@@ -185,15 +162,20 @@ export async function renameMCardFile(
185
162
  // Note: content, hash, detectedType, epistemicStatus, and subclass remain strictly identical (INV-284-02)
186
163
  };
187
164
 
188
- // 1. Update studioMCardFs CAS handle registration
165
+ // 1. Delegate rename directly to kernel relocate (DoD-03-6, INV-CAS-05)
189
166
  try {
190
- const coreHandle = Handle.parse(newHandle);
191
- const coreHash = ContentHash.parse(existingNode.hash);
192
- studioMCardFs.storageBackend.registerHandle(coreHandle, coreHash);
193
- const slashHandle = Handle.parse(newPath);
194
- studioMCardFs.storageBackend.registerHandle(slashHandle, coreHash);
167
+ studioMCardFs.relocate(oldPath, newPath);
195
168
  } catch {
196
- // Ignore handle parsing errors in test mocks
169
+ try {
170
+ studioMCardFs.relocate(oldHandle, newHandle);
171
+ } catch {
172
+ // Fall back to handle registration in test mocks
173
+ try {
174
+ const coreHandle = Handle.parse(newHandle);
175
+ const coreHash = ContentHash.parse(existingNode.hash);
176
+ studioMCardFs.storageBackend.registerHandle(coreHandle, coreHash);
177
+ } catch {}
178
+ }
197
179
  }
198
180
 
199
181
  // 2. Update $mcardTree atomically
@@ -15,30 +15,24 @@ const WS_DIR = PATHS.paths.workspace_dirname;
15
15
  const DB_NAME = 'clm_workbench_db';
16
16
  const DB_VERSION = 2;
17
17
 
18
- export const STORE_CAS = 'clm_cas_blobs';
19
- export const STORE_HANDLES = 'clm_handle_registry';
20
- export const STORE_HISTORY = 'clm_handle_history';
21
- export const STORE_SNAPSHOTS = 'clm_sqlite_snapshots';
22
- const STORE_LEGACY = 'clm_content_memory_db';
23
-
24
- export function openIndexedDb(): Promise<IDBDatabase> {
25
- return new Promise((resolve, reject) => {
26
- if (typeof window === 'undefined' || !window.indexedDB) {
27
- return reject(new Error('IndexedDB not available'));
28
- }
29
- const req = window.indexedDB.open(DB_NAME, DB_VERSION);
30
- req.onupgradeneeded = () => {
31
- const db = req.result;
32
- if (!db.objectStoreNames.contains(STORE_CAS)) db.createObjectStore(STORE_CAS, { keyPath: 'hash' });
33
- if (!db.objectStoreNames.contains(STORE_HANDLES)) db.createObjectStore(STORE_HANDLES, { keyPath: 'handle' });
34
- if (!db.objectStoreNames.contains(STORE_HISTORY)) db.createObjectStore(STORE_HISTORY, { keyPath: 'id', autoIncrement: true });
35
- if (!db.objectStoreNames.contains(STORE_SNAPSHOTS)) db.createObjectStore(STORE_SNAPSHOTS, { keyPath: 'id' });
36
- if (!db.objectStoreNames.contains(STORE_LEGACY)) db.createObjectStore(STORE_LEGACY);
37
- };
38
- req.onsuccess = () => resolve(req.result);
39
- req.onerror = () => reject(req.error);
40
- });
41
- }
18
+ import {
19
+ openMigrationIndexedDb as openIndexedDb,
20
+ STORE_CAS,
21
+ STORE_HANDLES,
22
+ STORE_HISTORY,
23
+ STORE_SNAPSHOTS,
24
+ STORE_LEGACY,
25
+ migrateAndRetireLegacyIndexedDb,
26
+ } from './vfsMigration';
27
+
28
+ export {
29
+ openIndexedDb,
30
+ STORE_CAS,
31
+ STORE_HANDLES,
32
+ STORE_HISTORY,
33
+ STORE_SNAPSHOTS,
34
+ migrateAndRetireLegacyIndexedDb,
35
+ };
42
36
 
43
37
  export async function idbGet<T>(storeName: string, key: IDBValidKey): Promise<T | undefined> {
44
38
  try {
@@ -91,6 +85,7 @@ async function performPersistenceFlush(): Promise<void> {
91
85
  const casStore = tx.objectStore(STORE_CAS);
92
86
  const handleStore = tx.objectStore(STORE_HANDLES);
93
87
 
88
+ handleStore.clear();
94
89
  for (const n of wsEntries) {
95
90
  if (n.hash && n.content !== undefined) {
96
91
  casStore.put({ hash: n.hash, content: n.content, mimeType: n.mimeType, size: typeof n.content === 'string' ? n.content.length : (n.content as any)?.byteLength || 0 });
@@ -49,18 +49,20 @@ export async function syncMCardVfsWithServer(
49
49
 
50
50
  // Entering local-db -> restore the database projection, never trust directory nodes
51
51
  if (activeScope === 'local-db') {
52
- let localTree = localDbTreeSnapshot;
53
- if (Object.keys(localTree).length === 0) {
54
- if (typeof window !== 'undefined') {
55
- await hydrateFromIndexedDb();
52
+ if (lastScope !== 'local-db') {
53
+ let localTree = localDbTreeSnapshot;
54
+ if (Object.keys(localTree).length === 0) {
55
+ if (typeof window !== 'undefined') {
56
+ await hydrateFromIndexedDb();
57
+ }
58
+ localTree = { ...$mcardTree.get() };
59
+ localDbTreeSnapshot = localTree;
60
+ } else {
61
+ $mcardTree.set(localTree);
56
62
  }
57
- localTree = { ...$mcardTree.get() };
58
- localDbTreeSnapshot = localTree;
59
- } else {
60
- $mcardTree.set(localTree);
61
63
  }
62
64
  lastScope = activeScope;
63
- return localTree;
65
+ return $mcardTree.get();
64
66
  }
65
67
 
66
68
  // Return cached read-only directory tree if available and not forced
@@ -124,20 +126,56 @@ export async function federateAllScopesIntoTree(
124
126
  const data = await res.json();
125
127
  if (!data.success || !Array.isArray(data.files)) throw new Error('Malformed tree response');
126
128
 
127
- const merged: Record<string, MCardFileNode> = { ...$mcardTree.get() };
129
+ const current = $mcardTree.get();
130
+ const merged: Record<string, MCardFileNode> = {};
128
131
  for (const file of data.files as MCardFileNode[]) {
129
132
  const handle = file.handle || file.path;
130
133
  const fileScope = (file as any).scope || PATHS.paths.assets_dirname;
131
- const existing = merged[handle];
132
- if (!force && existing && typeof existing.content === 'string' && existing.content.length > 0) {
133
- continue;
134
+ const existing = current[handle];
135
+ const isPlaceholder = typeof existing?.content === 'string' && existing.content.startsWith('Content-addressed MCard:');
136
+ const mime = (file.mimeType || '').toLowerCase();
137
+ const isMedia =
138
+ (mime.startsWith('image/') && mime !== 'image/svg+xml') ||
139
+ mime.startsWith('audio/') ||
140
+ mime.startsWith('video/') ||
141
+ mime.startsWith('font/') ||
142
+ mime === 'application/pdf' ||
143
+ mime.startsWith('model/');
144
+
145
+ const isReadOnly = typeof file.readOnly === 'boolean' ? file.readOnly : (fileScope !== WS_DIR);
146
+ if (!force && existing && typeof existing.content === 'string' && existing.content.length > 0 && !isPlaceholder && !isMedia) {
147
+ merged[handle] = { ...file, ...existing, scope: fileScope, readOnly: isReadOnly };
148
+ } else {
149
+ merged[handle] = { ...file, scope: fileScope, readOnly: isReadOnly };
150
+ }
151
+ }
152
+
153
+ // Preserve unsaved in-memory drafts that are not yet on the server
154
+ for (const [handle, node] of Object.entries(current)) {
155
+ if (merged[handle]) continue;
156
+ if ((node as any).isDirty || (node as any).isDraft) {
157
+ merged[handle] = node;
134
158
  }
135
- merged[handle] = { ...file, scope: fileScope, readOnly: fileScope !== WS_DIR };
136
159
  }
137
160
 
138
- $mcardTree.set(merged);
139
- // Persist the federated workspace set so it survives a reload (INV-EX-09).
140
- triggerIndexedDbSync();
161
+ const currentKeys = Object.keys(current);
162
+ const mergedKeys = Object.keys(merged);
163
+ let changed = currentKeys.length !== mergedKeys.length;
164
+ if (!changed) {
165
+ for (const k of mergedKeys) {
166
+ const a = current[k];
167
+ const b = merged[k];
168
+ if (!a || !b || a.hash !== b.hash || a.scope !== b.scope || a.path !== b.path || a.content !== b.content) {
169
+ changed = true;
170
+ break;
171
+ }
172
+ }
173
+ }
174
+
175
+ if (changed || force) {
176
+ $mcardTree.set(merged);
177
+ triggerIndexedDbSync();
178
+ }
141
179
  return merged;
142
180
  } catch (err) {
143
181
  console.warn('[vfsSync] Multi-scope federation failed:', err);
@@ -36,12 +36,8 @@ export function getMCardHashHistory(handleOrPath: string): Array<{ hash: string;
36
36
  for (const r of historyRecords) {
37
37
  const hex = r.previousHash.asHex();
38
38
  const key = `${hex}:${r.changedAt}`;
39
- if (!seen.has(key)) {
40
- seen.add(key);
41
- result.push({ hash: hex, changedAt: r.changedAt });
42
- }
39
+ if (!seen.has(key)) { seen.add(key); result.push({ hash: hex, changedAt: r.changedAt }); }
43
40
  }
44
-
45
41
  return result;
46
42
  } catch {
47
43
  return [];
@@ -54,6 +50,7 @@ export interface MCardVersionItem {
54
50
  changedAt: string;
55
51
  isHead: boolean;
56
52
  isCurrentView: boolean;
53
+ kind?: string;
57
54
  }
58
55
 
59
56
  export interface MCardVersionListResult {
@@ -89,55 +86,47 @@ function computeMCardVersionList(
89
86
  }
90
87
  }
91
88
 
92
- // 2. Get history records
89
+ // 2. Get history records & transitions (Sprint CAS-03, DoD-03-6)
90
+ const transitions = (studioMCardFs.transitions ? (studioMCardFs.transitions(targetPath).concat(studioMCardFs.transitions(targetHandle))) : []);
93
91
  const hist = studioMCardFs.history(targetPath).concat(studioMCardFs.history(targetHandle));
94
92
  const seen = new Set<string>();
95
- const dedupeHist: Array<{ hash: string; changedAt: string }> = [];
93
+ const dedupeHist: Array<{ hash: string; changedAt: string; kind?: string }> = [];
96
94
 
97
95
  for (const h of hist) {
98
96
  const hex = h.previousHash.asHex();
99
97
  const key = `${hex}:${h.changedAt}`;
100
- if (!seen.has(key) && hex !== headHash) {
101
- seen.add(key);
102
- dedupeHist.push({ hash: hex, changedAt: h.changedAt });
103
- }
98
+ if (!seen.has(key) && hex !== headHash) { seen.add(key); dedupeHist.push({ hash: hex, changedAt: h.changedAt, kind: (h as any).kind }); }
104
99
  }
105
100
 
106
- const versions: MCardVersionItem[] = [];
107
- // Oldest historical revisions: v1, v2, ...
108
- dedupeHist.forEach((h, idx) => {
109
- versions.push({
110
- version: idx + 1,
111
- hash: h.hash,
112
- changedAt: h.changedAt,
113
- isHead: false,
114
- isCurrentView: currentlyViewedHash ? currentlyViewedHash === h.hash : false,
115
- });
116
- });
101
+ const versions: MCardVersionItem[] = dedupeHist.map((h, idx) => ({
102
+ version: idx + 1,
103
+ hash: h.hash,
104
+ changedAt: h.changedAt,
105
+ isHead: false,
106
+ isCurrentView: currentlyViewedHash === h.hash,
107
+ kind: h.kind || 'UPDATE',
108
+ }));
117
109
 
118
110
  // Active HEAD revision: v(N)
119
111
  if (headHash) {
120
- const isHeadView = currentlyViewedHash ? currentlyViewedHash === headHash : true;
121
112
  let headChangedAt = "—";
122
- try {
123
- headChangedAt = studioMCardFs.statFile(targetPath).updatedAt;
124
- } catch {
125
- try {
126
- headChangedAt = studioMCardFs.statFile(targetHandle).updatedAt;
127
- } catch {
113
+ try { headChangedAt = studioMCardFs.statFile(targetPath).updatedAt; }
114
+ catch {
115
+ try { headChangedAt = studioMCardFs.statFile(targetHandle).updatedAt; }
116
+ catch {
128
117
  const metaTime = existing?.coreCard?.metadata.get('updatedAt') || existing?.coreCard?.metadata.get('timestamp');
129
- if (metaTime && (typeof metaTime === 'string' || typeof metaTime === 'number')) {
130
- headChangedAt = new Date(metaTime).toISOString();
131
- }
118
+ if (metaTime) headChangedAt = new Date(metaTime as string | number).toISOString();
132
119
  }
133
120
  }
134
-
121
+ const latestTransition = transitions[transitions.length - 1];
122
+ const headKind = latestTransition?.kind || (dedupeHist.length === 0 ? 'CREATE' : 'UPDATE');
135
123
  versions.push({
136
124
  version: versions.length + 1,
137
125
  hash: headHash,
138
126
  changedAt: headChangedAt,
139
127
  isHead: true,
140
- isCurrentView: isHeadView,
128
+ isCurrentView: currentlyViewedHash ? currentlyViewedHash === headHash : true,
129
+ kind: headKind,
141
130
  });
142
131
  }
143
132