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.
- package/README.md +3 -0
- package/astro.config.mjs +41 -2
- package/cli/lib/runtimeContext.mjs +6 -3
- package/dist/client/_astro/{ChartAnalyticsViewlet.jrwIemvb.js → ChartAnalyticsViewlet.CBW-JyA3.js} +1 -1
- package/dist/client/_astro/{ClmPcardViewlet.C-fU7oZf.js → ClmPcardViewlet.cvKsR2ng.js} +2 -2
- package/dist/client/_astro/{D3GraphViewlet.BCZl0b2U.js → D3GraphViewlet.8YEIrCGL.js} +1 -1
- package/dist/client/_astro/DockviewSpatialWorkbench.BTd66LPl.js +12 -0
- package/dist/client/_astro/DocumentViewlets.KY1HcNka.js +2 -0
- package/dist/client/_astro/DxfViewlet.B3N5zpZR.js +1 -0
- package/dist/client/_astro/{ExcalidrawWhiteboardViewlet.CFpPYSdn.js → ExcalidrawWhiteboardViewlet.CMJGCQN4.js} +1 -1
- package/dist/client/_astro/{FaroVCardSpanInstrumenter.un8kDMWv.js → FaroVCardSpanInstrumenter.ClIqZujq.js} +1 -1
- package/dist/client/_astro/{FontSpecimenViewlet.D7Aw2xBZ.js → FontSpecimenViewlet.ChIyr0B8.js} +1 -1
- package/dist/client/_astro/HeadMeta.astro_astro_type_script_index_0_lang.D3FSc061.js +1 -0
- package/dist/client/_astro/{ImageViewlet.D4FN87n_.js → ImageViewlet.Cs-u7-wt.js} +1 -1
- package/dist/client/_astro/{KatexFormulaViewlet.CzhdIOw8.js → KatexFormulaViewlet.0nOzV_qD.js} +1 -1
- package/dist/client/_astro/{KoishiChatViewlet.5mepQvLX.js → KoishiChatViewlet.DLsMmwdb.js} +4 -4
- package/dist/client/_astro/{MCardLibraryHarness.DE8KeghO.js → MCardLibraryHarness.WBT9W10S.js} +1 -1
- package/dist/client/_astro/{MarkdownViewlet.CRuuXXmF.js → MarkdownViewlet.BIolkNXf.js} +25 -25
- package/dist/client/_astro/{MermaidDiagramViewlet.eW6sk-rF.js → MermaidDiagramViewlet.CkRk7QsS.js} +1 -1
- package/dist/client/_astro/PCardRendererBridge.DhaRSprd.js +1 -0
- package/dist/client/_astro/RendererPCardRegistry.brM2KiQs.js +1 -0
- package/dist/client/_astro/{SchemaYamlViewlet.ZJBvxItR.js → SchemaYamlViewlet.Bc7nkK4M.js} +1 -1
- 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
- package/dist/client/_astro/{Spatial3dViewlet.DnVMBENJ.js → Spatial3dViewlet.C-jjhr0A.js} +1 -1
- package/dist/client/_astro/{StudioLayout.CBgiVbeb.css → StudioLayout.CX8XGtZV.css} +1 -1
- package/dist/client/_astro/StudioWorkbench.B1QwGHWM.js +7 -0
- package/dist/client/_astro/{SvgViewlet.BCje7Qqb.js → SvgViewlet.uGxvb06H.js} +1 -1
- package/dist/client/_astro/{TerminalView.C_Ksz6lT.js → TerminalView.DP7G7E1m.js} +1 -1
- package/dist/client/_astro/{ThemeSettingsViewlet.DJpjQQ0Z.js → ThemeSettingsViewlet.UaTHcGnF.js} +1 -1
- package/dist/client/_astro/{TikzDiagramViewlet.CXb1A8nf.js → TikzDiagramViewlet.O8MJyXfT.js} +1 -1
- package/dist/client/_astro/VideoPlayerViewlet.-ycmo3kY.js +1 -0
- package/dist/client/_astro/WebappZenViewlet.PNce4u2T.js +1 -0
- package/dist/client/_astro/{WelcomeViewport.BiYwLh6l.js → WelcomeViewport.CZ6RxGSw.js} +1 -1
- package/dist/client/_astro/{agentIdentityCredentialService.UzMMwBwv.js → agentIdentityCredentialService.BEtZzBlO.js} +1 -1
- package/dist/client/_astro/cardTypeDetector.C2HH5RnU.js +1 -0
- package/dist/client/_astro/disposable.BmlxZrDf.js +1 -0
- package/dist/client/_astro/{markdownService.BgWjyJ57.js → markdownService.CpuKl0vp.js} +1 -1
- package/dist/client/_astro/{mcardStore.CT-ollfl.js → mcardStore.nSWnzeLg.js} +1 -1
- package/dist/client/_astro/mcardVfs.BSdys1Y7.js +3 -0
- package/dist/client/_astro/pathsConfig.CSBBSzwH.js +2 -0
- package/dist/client/_astro/{polyfills._3wYPjZf.js → polyfills.Bi7kO8cu.js} +1 -1
- package/dist/client/_astro/rendererEventBus.DirFDmGw.js +1 -0
- package/dist/client/_astro/themeStore.BajxvCga.js +1 -0
- package/dist/client/_astro/{tikzCompiler.fe3qomFY.js → tikzCompiler.-fXMNQpz.js} +1 -1
- package/dist/client/_astro/{useMCardHydration.7Z-HfBh5.js → useMCardHydration.Bjj_N5Gv.js} +1 -1
- package/dist/client/_astro/vendor-clm-kernel.B0kxq3g4.js +108 -0
- package/dist/client/_astro/{vfsHandles.IX_wTpw_.js → vfsHandles.D4Pq18pW.js} +1 -1
- package/dist/client/_astro/vfsPersistence.DVrd1BZj.js +1 -0
- package/dist/client/_astro/{vfsTransactions.C_IQQg0s.js → vfsTransactions.DBNtFuRz.js} +1 -1
- package/dist/client/_astro/{workspaceStore.CD0kAVAl.js → workspaceStore.DUHW2YBc.js} +1 -1
- package/dist/server/chunks/{_.._5gPhVOLM.mjs → _.._CoQKwo62.mjs} +137 -91
- package/dist/server/chunks/{_handle__D_cIJYrU.mjs → _handle__D8dKQPUS.mjs} +3 -3
- package/dist/server/chunks/{cardTypeDetector_CyW1Xnmy.mjs → cardTypeDetector_C55M_HWS.mjs} +9 -0
- package/dist/server/chunks/{cards_B89BvF6W.mjs → cards_rVOc8K6H.mjs} +2 -2
- package/dist/server/chunks/cas_DTxlZ4Le.mjs +68 -0
- package/dist/server/chunks/{dispatch_DOwSKukU.mjs → dispatch_BTW4E_BJ.mjs} +8 -7
- package/dist/server/chunks/{dispatch_CxWKiHpn.mjs → dispatch_MbkljUxD.mjs} +8 -8
- package/dist/server/chunks/{export_DRouradA.mjs → export_DkEwDE2T.mjs} +3 -3
- package/dist/server/chunks/{health_Dfa5I0-X.mjs → health_cRt0M0yu.mjs} +1 -1
- package/dist/server/chunks/{mcard-library_7Wzoihkm.mjs → mcard-library_CLHvyslV.mjs} +1 -1
- package/dist/server/chunks/{mcardVfs_CeezzRvt.mjs → mcardVfs_DvNburKb.mjs} +5 -30
- package/dist/server/chunks/{move__RFvIDkq.mjs → move_DYcaXBLV.mjs} +6 -6
- package/dist/server/chunks/{pathsConfig_CgNYYLVm.mjs → pathsConfig_Dack-p2f.mjs} +13 -3
- package/dist/server/chunks/{proxy_CrWJQIBe.mjs → proxy_CMbbdBPW.mjs} +2 -2
- package/dist/server/chunks/{raw_DzNDaDVP.mjs → raw_C97sJWhg.mjs} +59 -26
- package/dist/server/chunks/{serverBootstrap_XKo2s6Ha.mjs → serverBootstrap_BDdSRIu5.mjs} +2 -2
- package/dist/server/chunks/tree_BwmO-pTe.mjs +186 -0
- package/dist/server/chunks/vfsCore_DIKpk-pk.mjs +98 -0
- package/dist/server/chunks/{vfsTreeScan_CKp7kMt9.mjs → vfsTreeScan_CRoCluPB.mjs} +18 -10
- package/dist/server/chunks/workspaceRoot_CRx3taID.mjs +157 -0
- package/dist/server/chunks/{write_popiFsO7.mjs → write_BLsmsTIx.mjs} +6 -5
- package/dist/server/chunks/{ws-server-init_DUjuR2-o.mjs → ws-server-init_Cfft7U5u.mjs} +343 -298
- package/dist/server/entry.mjs +1 -1
- package/dist/server/entry2.mjs +67 -28
- package/dist/server/virtual_astro_middleware.mjs +2 -2
- package/package.json +2 -2
- package/src/components/studio/views/cardViewlets/ClmRegistryComponentViewlet.tsx +133 -0
- package/src/components/studio/views/cardViewlets/DxfViewlet.tsx +230 -0
- package/src/components/studio/views/cardViewlets/VideoPlayerViewlet.tsx +4 -4
- package/src/components/studio/views/cardViewlets/coreViewletDefs.ts +2 -2
- package/src/components/studio/views/cardViewlets/documents/AudioPlayerViewlet.tsx +15 -3
- package/src/components/studio/views/cardViewlets/documents/PdfViewlet.tsx +25 -7
- package/src/components/studio/views/cardViewlets/markdown/stages/wikilinkStage.ts +2 -1
- package/src/components/studio/views/cardViewlets/mediaViewletDefs.ts +21 -1
- package/src/components/studio/views/cardViewlets/webapp/WebappCanvas.tsx +40 -15
- package/src/components/studio/views/cardViewlets/webapp/WebappDevicePresetBar.tsx +108 -0
- package/src/components/studio/views/cardViewlets/webapp/WebappZenViewlet.tsx +23 -30
- package/src/components/studio/views/fileTree/MCardFileTree.tsx +71 -54
- package/src/components/studio/views/fileTree/hooks/useFileTreeSync.ts +0 -1
- package/src/components/studio/views/fileTree/hooks/usePartitionedTrees.ts +68 -23
- package/src/components/studio/views/fileTree/hooks/useSectionAccordion.ts +21 -11
- package/src/components/studio/views/functions/UnifiedFunctionExplorerViewlet.tsx +168 -0
- package/src/components/studio/views/history/HistoryPanel.tsx +110 -0
- package/src/components/studio/views/lineage/LineagePanel.tsx +152 -0
- package/src/components/studio/views/navigation/HandleLineageDrawer.tsx +89 -0
- package/src/components/studio/views/navigation/MultiCardCollectionBrowser.tsx +154 -0
- package/src/components/studio/views/pills/HashPill.tsx +101 -0
- package/src/components/studio/views/residency/ResidencyIndicator.tsx +82 -0
- package/src/config/app_config.json +3 -3
- package/src/core/projection/catalog.ts +105 -0
- package/src/core/projection/collection.ts +148 -0
- package/src/core/projection/handleSubscription.ts +132 -0
- package/src/core/projection/index.ts +4 -0
- package/src/core/projection/selectors.ts +29 -0
- package/src/core/projection/views.ts +242 -0
- package/src/core/refinement/designMetrics.ts +104 -0
- package/src/core/refinement/fibrationProjector.ts +142 -0
- package/src/core/refinement/lagrangianEngine.ts +137 -0
- package/src/core/refinement/refinementCommands.ts +82 -0
- package/src/core/viewport/deviceArchetypeRegistry.ts +177 -0
- package/src/core/viewport/viewportAudit.ts +150 -0
- package/src/edge/storeFilter.d.ts +4 -0
- package/src/edge/storeFilter.js +54 -0
- package/src/edge/storeFilter.ts +52 -0
- package/src/lib/cryptoPolyfill.js +77 -1
- package/src/lib/fsPolyfill.js +65 -0
- package/src/lib/urlPolyfill.js +21 -0
- package/src/lib/zlibPolyfill.js +35 -0
- package/src/packages/mcard-studio/package.json +2 -2
- package/src/packages/mcard-studio/type/legacyMapping.ts +5 -0
- package/src/packages/mcard-studio/viewlets/manifests.ts +2 -0
- package/src/packages/mcard-studio/viewlets/moduleMap.ts +12 -0
- package/src/packages/mcard-studio/viewlets/refinementManifests.ts +114 -0
- package/src/pages/api/dispatch.ts +3 -2
- package/src/pages/api/vfs/cas.ts +114 -0
- package/src/pages/api/vfs/move.ts +5 -5
- package/src/pages/api/vfs/raw.ts +72 -27
- package/src/pages/api/vfs/tree.ts +130 -11
- package/src/pages/api/vfs/write.ts +5 -4
- package/src/server/api/kernelDispatch.ts +8 -8
- package/src/server/artifactCollectionService.ts +4 -7
- package/src/server/artifactRepository.ts +4 -3
- package/src/server/clmRunner.mjs +1 -1
- package/src/server/collectionOwner.mjs +5 -5
- package/src/server/effects/executionPersistenceService.mjs +11 -11
- package/src/server/effects/resultSealingService.mjs +2 -2
- package/src/server/fileIngestService.mjs +21 -9
- package/src/server/fileWatcherService.mjs +4 -1
- package/src/server/handlers/fileChangeHandler.mjs +18 -10
- package/src/server/handlers/saveExecutionLogHandler.mjs +6 -6
- package/src/server/notificationService.mjs +14 -1
- package/src/server/scripts/buildSeedingMemory.mjs +3 -3
- package/src/server/serverMemoryRepository.ts +41 -59
- package/src/server/vfsTreeScan.ts +16 -10
- package/src/server/workspaceRoot.ts +143 -5
- package/src/services/cardTypeDetector.ts +4 -0
- package/src/services/databaseSyncService.ts +30 -46
- package/src/services/namespaceProtocolClient.ts +221 -0
- package/src/services/renderers/pcard/RendererPCardRegistry.ts +4 -66
- package/src/services/renderers/pcard/modalitySpecs.ts +125 -0
- package/src/services/renderers/pcard/types.ts +7 -1
- package/src/services/renderers/rendererEventBus.ts +5 -3
- package/src/services/unifiedFunctionExecutionService.ts +145 -0
- package/src/services/vfs/vfsCore.ts +12 -1
- package/src/services/vfs/vfsMigration.ts +95 -0
- package/src/services/vfs/vfsMutations.ts +17 -35
- package/src/services/vfs/vfsPersistence.ts +19 -24
- package/src/services/vfs/vfsSync.ts +55 -17
- package/src/services/vfs/vfsVersions.ts +23 -34
- package/src/services/workbenchExecutionPolicy.ts +183 -0
- package/src/stores/mcardCollectionStore.ts +2 -0
- package/src/styles/dockview.css +34 -0
- package/src/ui/viewlets/FibrationRefinementViewlet.tsx +155 -0
- package/src/ui/viewlets/PetriConformanceViewlet.tsx +166 -0
- package/src/ui/viewlets/ResponsiveViewportLabViewlet.tsx +175 -0
- package/src/ui/viewlets/SprintGovernanceViewlet.tsx +176 -0
- package/src/ui/viewlets/viewletFocus.ts +35 -0
- package/src/ui/viewlets/viewportLabParts.tsx +190 -0
- package/dist/client/_astro/DockviewSpatialWorkbench.B_I1GJHw.js +0 -12
- package/dist/client/_astro/DocumentViewlets.B53IqmpY.js +0 -2
- package/dist/client/_astro/HeadMeta.astro_astro_type_script_index_0_lang.VDRYJCM-.js +0 -1
- package/dist/client/_astro/PCardRendererBridge.oxVKc0gN.js +0 -1
- package/dist/client/_astro/RendererPCardRegistry.CWjYZs2H.js +0 -1
- package/dist/client/_astro/StudioWorkbench.Blo5oSIw.js +0 -7
- package/dist/client/_astro/VideoPlayerViewlet.CmECt7yT.js +0 -1
- package/dist/client/_astro/WebappZenViewlet.whCmGVHR.js +0 -1
- package/dist/client/_astro/__vite-browser-external.CQZnr-r3.js +0 -1
- package/dist/client/_astro/cardTypeDetector.Ci4APwhX.js +0 -1
- package/dist/client/_astro/disposable.Dsb0sbRP.js +0 -1
- package/dist/client/_astro/mcardVfs.2UOw9Z-r.js +0 -3
- package/dist/client/_astro/pathsConfig.D0hV34p7.js +0 -2
- package/dist/client/_astro/rendererEventBus.DMH9afq9.js +0 -1
- package/dist/client/_astro/themeStore.CEt0e54l.js +0 -1
- package/dist/client/_astro/vendor-clm-kernel.Bvk3XHk2.js +0 -116
- package/dist/client/_astro/vfsPersistence.BuhXYeSb.js +0 -1
- package/dist/server/chunks/cryptoPolyfill_99rxUwYC.mjs +0 -180
- package/dist/server/chunks/kernelHash_DRaj51hY.mjs +0 -5
- package/dist/server/chunks/tree_CE2BhvyJ.mjs +0 -76
- package/dist/server/chunks/vfsCore_B6nCiBl5.mjs +0 -21
- package/dist/server/chunks/workspaceRoot_DVSUbYkd.mjs +0 -71
- package/src/server/kernelHash.ts +0 -22
- package/src/server/storage/cardCollection.ts +0 -94
- package/src/server/storage/index.ts +0 -3
- package/src/server/storage/mcard.ts +0 -99
- package/src/server/storage/sqliteNodeEngine.ts +0 -121
- /package/dist/server/chunks/{StudioLayout_B5ZnlqjF.mjs → StudioLayout_taayQJ5b.mjs} +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{n as e}from"./rolldown-runtime.Dd_uD5pT.js";import{F as t}from"./vendor-clm-kernel.Bvk3XHk2.js";import{h as n}from"./themeStore.CEt0e54l.js";import{a as r,y as i}from"./mcardStore.CT-ollfl.js";import{t as a}from"./pathsConfig.D0hV34p7.js";var o=class{options;isFlushing=!1;flushPromise=null;currentGeneration=0;retryAttempts=0;debounceTimer=null;state=`idle`;constructor(e){this.options=e}scheduleFlush(e=300){this.debounceTimer&&clearTimeout(this.debounceTimer),this.debounceTimer=setTimeout(()=>{this.flush().catch(e=>console.error(`[StorageSupervisor] Flush error:`,e))},e)}async flush(){return this.isFlushing&&this.flushPromise?this.flushPromise:(this.isFlushing=!0,this.transition(`saving`),this.flushPromise=(async()=>{try{await this.options.flush(),this.currentGeneration++,this.retryAttempts=0,this.transition(`persistent`)}catch(e){throw this.transition(`error`),e}finally{this.isFlushing=!1,this.flushPromise=null}})(),this.flushPromise)}handleStaleConflict(e,t){this.transition(`stale`),console.warn(`[StorageSupervisor] Stale writer conflict: expected gen ${e}, found ${t}`)}async retryFlush(){try{return await this.flush(),!0}catch{return this.retryAttempts++,!1}}getState(){return this.state}getCurrentGeneration(){return this.currentGeneration}getRetryAttempts(){return this.retryAttempts}dispose(){this.debounceTimer&&=(clearTimeout(this.debounceTimer),null),this.isFlushing=!1,this.flushPromise=null}transition(e){this.state=e,this.options.onStateChange?.(e)}},s=e({STORE_CAS:()=>d,STORE_HANDLES:()=>f,STORE_HISTORY:()=>p,STORE_SNAPSHOTS:()=>m,getSqliteBytesFromIndexedDb:()=>T,hydrateFromIndexedDb:()=>C,idbGet:()=>_,idbGetAll:()=>v,idbPut:()=>y,loadCardsFromIndexedDb:()=>E,openIndexedDb:()=>g,saveSqliteBytesToIndexedDb:()=>w,triggerIndexedDbSync:()=>S,vfsStorageSupervisor:()=>x}),c=a.paths.workspace_dirname,l=`clm_workbench_db`,u=2,d=`clm_cas_blobs`,f=`clm_handle_registry`,p=`clm_handle_history`,m=`clm_sqlite_snapshots`,h=`clm_content_memory_db`;function g(){return new Promise((e,t)=>{if(typeof window>`u`||!window.indexedDB)return t(Error(`IndexedDB not available`));let n=window.indexedDB.open(l,u);n.onupgradeneeded=()=>{let e=n.result;e.objectStoreNames.contains(`clm_cas_blobs`)||e.createObjectStore(d,{keyPath:`hash`}),e.objectStoreNames.contains(`clm_handle_registry`)||e.createObjectStore(f,{keyPath:`handle`}),e.objectStoreNames.contains(`clm_handle_history`)||e.createObjectStore(p,{keyPath:`id`,autoIncrement:!0}),e.objectStoreNames.contains(`clm_sqlite_snapshots`)||e.createObjectStore(m,{keyPath:`id`}),e.objectStoreNames.contains(h)||e.createObjectStore(h)},n.onsuccess=()=>e(n.result),n.onerror=()=>t(n.error)})}async function _(e,t){try{let n=await g();return new Promise((r,i)=>{let a=n.transaction(e,`readonly`).objectStore(e).get(t);a.onsuccess=()=>r(a.result),a.onerror=()=>i(a.error)})}catch{return}}async function v(e){try{let t=await g();return new Promise((n,r)=>{let i=t.transaction(e,`readonly`).objectStore(e).getAll();i.onsuccess=()=>n(i.result||[]),i.onerror=()=>r(i.error)})}catch{return[]}}async function y(e,t,n){try{let r=await g();return new Promise((i,a)=>{let o=r.transaction(e,`readwrite`).objectStore(e),s=n===void 0?o.put(t):o.put(t,n);s.onsuccess=()=>i(),s.onerror=()=>a(s.error)})}catch{}}async function b(){if(typeof window>`u`||!window.indexedDB)return;let e=i.get(),t=Object.values(e),r=`${c}:`,a=t.filter(e=>e.handle.startsWith(r)||e.scope===c||e.path.startsWith(`${c}/`)),o=(await g()).transaction([d,f,p,m,h],`readwrite`),s=o.objectStore(d),l=o.objectStore(f);for(let e of a)e.hash&&e.content!==void 0&&s.put({hash:e.hash,content:e.content,mimeType:e.mimeType,size:typeof e.content==`string`?e.content.length:e.content?.byteLength||0}),l.put({handle:e.handle,scope:c,path:e.path,name:e.name,hash:e.hash,detectedType:e.detectedType,epistemicStatus:e.epistemicStatus,mtime:e.mtime||Date.now()});let u=n.storageBackend;if(u&&typeof u.exportBinary==`function`){let e=u.exportBinary();e&&o.objectStore(m).put({id:`latest`,bytes:e,mtime:Date.now()})}let _=a.map(e=>({handle:e.handle,hash:e.hash,path:e.path,name:e.name,mimeType:e.mimeType,detectedType:e.detectedType,epistemicStatus:e.epistemicStatus,readOnly:e.readOnly,subclass:e.subclass,content:e.content}));o.objectStore(h).put(_,`clm_cards`)}var x=new o({flush:b,onStateChange:e=>{r({isPersistent:e===`persistent`,lastSavedIso:new Date().toISOString(),supervisorState:e})}});function S(){let e=i.get(),t=Object.values(e),a=0;for(let e of t)typeof e.content==`string`?a+=e.content.length:e.content instanceof Uint8Array&&(a+=e.content.byteLength);let o=n.storageBackend.constructor.name,s=o.includes(`Sqlite`)?`sqlite`:o.includes(`SqlJs`)?`sqljs`:`memory`;r({backendType:s,cardCount:t.length,totalBytes:a,isPersistent:!0,lastSavedIso:new Date().toISOString()}),x.scheduleFlush(300)}async function C(){if(typeof window>`u`||!window.indexedDB)return!1;try{let e=await v(f),a=`${c}:`,o=e.filter(e=>e.scope===c||e.handle&&e.handle.startsWith(a)),s=i.get(),l=t.create(`did:clm:agent:idb`),u=0,p=0;if(o.length>0)for(let e of o){let t=``;if(e.hash){let n=await _(d,e.hash);n&&n.content!==void 0&&(t=n.content)}if(!s[e.handle]||!s[e.handle].content){let r=n.writeFile(e.path,t||``,l);s[e.handle]={...e,content:t,coreCard:r},u++}typeof t==`string`&&(p+=t.length)}else{let e=await _(h,`clm_cards`);if(Array.isArray(e)&&e.length>0){for(let t of e)if((t.path.startsWith(`${c}/`)||t.handle.startsWith(a))&&(!s[t.handle]||!s[t.handle].content)){let e=n.writeFile(t.path,t.content||``,l);s[t.handle]={...t,coreCard:e},u++}}}return u>0&&(i.set({...s}),r({cardCount:Object.keys(s).length,totalBytes:p,isPersistent:!0,lastSavedIso:new Date().toISOString()}),!0)}catch(e){return console.warn(`[MCardVFS] Failed to hydrate from IndexedDB:`,e),!1}}async function w(e){typeof window<`u`&&window.indexedDB&&await y(m,{id:`latest`,bytes:e,mtime:Date.now()})}async function T(){if(typeof window<`u`&&window.indexedDB)return(await _(m,`latest`))?.bytes}async function E(){if(typeof window<`u`&&window.indexedDB)return _(h,`clm_cards`)}export{s as i,w as n,S as r,C as t};
|
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
//#region src/lib/cryptoPolyfill.js
|
|
2
|
-
/**
|
|
3
|
-
* Browser-safe isomorphic crypto polyfill for Vite & Rollup client bundles.
|
|
4
|
-
* Provides createHash, randomUUID, randomBytes, and getRandomValues in browser context.
|
|
5
|
-
*/
|
|
6
|
-
function sha256Bytes(input) {
|
|
7
|
-
const bytes = typeof input === "string" ? new TextEncoder().encode(input) : input;
|
|
8
|
-
const K = [
|
|
9
|
-
1116352408,
|
|
10
|
-
1899447441,
|
|
11
|
-
3049323471,
|
|
12
|
-
3921009573,
|
|
13
|
-
961987163,
|
|
14
|
-
1508970993,
|
|
15
|
-
2453635748,
|
|
16
|
-
2870763221,
|
|
17
|
-
3624381080,
|
|
18
|
-
310598401,
|
|
19
|
-
607225278,
|
|
20
|
-
1426881987,
|
|
21
|
-
1925078388,
|
|
22
|
-
2162078206,
|
|
23
|
-
2614888103,
|
|
24
|
-
3248222580,
|
|
25
|
-
3835390401,
|
|
26
|
-
4022224774,
|
|
27
|
-
264347078,
|
|
28
|
-
604807628,
|
|
29
|
-
770255983,
|
|
30
|
-
1249150122,
|
|
31
|
-
1555081692,
|
|
32
|
-
1996064986,
|
|
33
|
-
2554220882,
|
|
34
|
-
2821834349,
|
|
35
|
-
2952996808,
|
|
36
|
-
3210313671,
|
|
37
|
-
3336571891,
|
|
38
|
-
3584528711,
|
|
39
|
-
113926993,
|
|
40
|
-
338241895,
|
|
41
|
-
666307205,
|
|
42
|
-
773529912,
|
|
43
|
-
1294757372,
|
|
44
|
-
1396182291,
|
|
45
|
-
1695183700,
|
|
46
|
-
1986661051,
|
|
47
|
-
2177026350,
|
|
48
|
-
2456956037,
|
|
49
|
-
2730485921,
|
|
50
|
-
2820302411,
|
|
51
|
-
3259730800,
|
|
52
|
-
3345764771,
|
|
53
|
-
3516065817,
|
|
54
|
-
3600352804,
|
|
55
|
-
4094571909,
|
|
56
|
-
275423344,
|
|
57
|
-
430227734,
|
|
58
|
-
506948616,
|
|
59
|
-
659060556,
|
|
60
|
-
883997877,
|
|
61
|
-
958139571,
|
|
62
|
-
1322822218,
|
|
63
|
-
1537002063,
|
|
64
|
-
1747873779,
|
|
65
|
-
1955562222,
|
|
66
|
-
2024104815,
|
|
67
|
-
2227730452,
|
|
68
|
-
2361852424,
|
|
69
|
-
2428436474,
|
|
70
|
-
2756734187,
|
|
71
|
-
3204031479,
|
|
72
|
-
3329325298
|
|
73
|
-
];
|
|
74
|
-
let h0 = 1779033703, h1 = 3144134277, h2 = 1013904242, h3 = 2773480762, h4 = 1359893119, h5 = 2600822924, h6 = 528734635, h7 = 1541459225;
|
|
75
|
-
const len = bytes.length;
|
|
76
|
-
const bitLen = len * 8;
|
|
77
|
-
const totalLen = len + (len % 64 < 56 ? 56 - len % 64 : 120 - len % 64) + 8;
|
|
78
|
-
const padded = new Uint8Array(totalLen);
|
|
79
|
-
padded.set(bytes);
|
|
80
|
-
padded[len] = 128;
|
|
81
|
-
const view = new DataView(padded.buffer);
|
|
82
|
-
view.setBigUint64(totalLen - 8, BigInt(bitLen), false);
|
|
83
|
-
const w = /* @__PURE__ */ new Uint32Array(64);
|
|
84
|
-
const rotr = (x, n) => x >>> n | x << 32 - n;
|
|
85
|
-
for (let i = 0; i < totalLen; i += 64) {
|
|
86
|
-
for (let t = 0; t < 16; t++) w[t] = view.getUint32(i + t * 4, false);
|
|
87
|
-
for (let t = 16; t < 64; t++) {
|
|
88
|
-
const s0 = rotr(w[t - 15], 7) ^ rotr(w[t - 15], 18) ^ w[t - 15] >>> 3;
|
|
89
|
-
const s1 = rotr(w[t - 2], 17) ^ rotr(w[t - 2], 19) ^ w[t - 2] >>> 10;
|
|
90
|
-
w[t] = w[t - 16] + s0 + w[t - 7] + s1 | 0;
|
|
91
|
-
}
|
|
92
|
-
let a = h0, b = h1, c = h2, d = h3, e = h4, f = h5, g = h6, h = h7;
|
|
93
|
-
for (let t = 0; t < 64; t++) {
|
|
94
|
-
const S1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);
|
|
95
|
-
const ch = e & f ^ ~e & g;
|
|
96
|
-
const temp1 = h + S1 + ch + K[t] + w[t] | 0;
|
|
97
|
-
const temp2 = (rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22)) + (a & b ^ a & c ^ b & c) | 0;
|
|
98
|
-
h = g;
|
|
99
|
-
g = f;
|
|
100
|
-
f = e;
|
|
101
|
-
e = d + temp1 | 0;
|
|
102
|
-
d = c;
|
|
103
|
-
c = b;
|
|
104
|
-
b = a;
|
|
105
|
-
a = temp1 + temp2 | 0;
|
|
106
|
-
}
|
|
107
|
-
h0 = h0 + a | 0;
|
|
108
|
-
h1 = h1 + b | 0;
|
|
109
|
-
h2 = h2 + c | 0;
|
|
110
|
-
h3 = h3 + d | 0;
|
|
111
|
-
h4 = h4 + e | 0;
|
|
112
|
-
h5 = h5 + f | 0;
|
|
113
|
-
h6 = h6 + g | 0;
|
|
114
|
-
h7 = h7 + h | 0;
|
|
115
|
-
}
|
|
116
|
-
const out = /* @__PURE__ */ new Uint8Array(32);
|
|
117
|
-
const outView = new DataView(out.buffer);
|
|
118
|
-
outView.setUint32(0, h0, false);
|
|
119
|
-
outView.setUint32(4, h1, false);
|
|
120
|
-
outView.setUint32(8, h2, false);
|
|
121
|
-
outView.setUint32(12, h3, false);
|
|
122
|
-
outView.setUint32(16, h4, false);
|
|
123
|
-
outView.setUint32(20, h5, false);
|
|
124
|
-
outView.setUint32(24, h6, false);
|
|
125
|
-
outView.setUint32(28, h7, false);
|
|
126
|
-
return out;
|
|
127
|
-
}
|
|
128
|
-
var Hash = class {
|
|
129
|
-
constructor(algorithm) {
|
|
130
|
-
this.algorithm = algorithm;
|
|
131
|
-
this.chunks = [];
|
|
132
|
-
}
|
|
133
|
-
update(data) {
|
|
134
|
-
if (typeof data === "string") this.chunks.push(new TextEncoder().encode(data));
|
|
135
|
-
else if (data instanceof Uint8Array) this.chunks.push(data);
|
|
136
|
-
else if (ArrayBuffer.isView(data)) this.chunks.push(new Uint8Array(data.buffer, data.byteOffset, data.byteLength));
|
|
137
|
-
return this;
|
|
138
|
-
}
|
|
139
|
-
digest(encoding) {
|
|
140
|
-
let totalLen = 0;
|
|
141
|
-
for (const c of this.chunks) totalLen += c.length;
|
|
142
|
-
const merged = new Uint8Array(totalLen);
|
|
143
|
-
let offset = 0;
|
|
144
|
-
for (const c of this.chunks) {
|
|
145
|
-
merged.set(c, offset);
|
|
146
|
-
offset += c.length;
|
|
147
|
-
}
|
|
148
|
-
const hashBytes = sha256Bytes(merged);
|
|
149
|
-
if (encoding === "hex") return Array.from(hashBytes).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
150
|
-
if (typeof Buffer !== "undefined" && typeof Buffer.from === "function") return Buffer.from(hashBytes);
|
|
151
|
-
return hashBytes;
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
function createHash(algorithm) {
|
|
155
|
-
return new Hash(algorithm);
|
|
156
|
-
}
|
|
157
|
-
function randomUUID() {
|
|
158
|
-
if (typeof globalThis !== "undefined" && globalThis.crypto && typeof globalThis.crypto.randomUUID === "function") return globalThis.crypto.randomUUID();
|
|
159
|
-
return "10000000-1000-4000-8000-100000000000".replace(/[018]/g, (c) => (c ^ crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(1))[0] & 15 >> c / 4).toString(16));
|
|
160
|
-
}
|
|
161
|
-
function getRandomValues(array) {
|
|
162
|
-
if (typeof globalThis !== "undefined" && globalThis.crypto && typeof globalThis.crypto.getRandomValues === "function") return globalThis.crypto.getRandomValues(array);
|
|
163
|
-
for (let i = 0; i < array.length; i++) array[i] = Math.floor(Math.random() * 256);
|
|
164
|
-
return array;
|
|
165
|
-
}
|
|
166
|
-
function randomBytes(size) {
|
|
167
|
-
const bytes = new Uint8Array(size);
|
|
168
|
-
getRandomValues(bytes);
|
|
169
|
-
if (typeof Buffer !== "undefined" && typeof Buffer.from === "function") return Buffer.from(bytes);
|
|
170
|
-
return bytes;
|
|
171
|
-
}
|
|
172
|
-
var cryptoPolyfill = {
|
|
173
|
-
createHash,
|
|
174
|
-
randomUUID,
|
|
175
|
-
getRandomValues,
|
|
176
|
-
randomBytes,
|
|
177
|
-
webcrypto: typeof globalThis !== "undefined" ? globalThis.crypto : void 0
|
|
178
|
-
};
|
|
179
|
-
//#endregion
|
|
180
|
-
export { cryptoPolyfill as n, createHash as t };
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { t as __exportAll } from "./rolldown-runtime_8H4AJuhK.mjs";
|
|
2
|
-
import { n as getWhitelistedDirectoryProjections, t as PATHS } from "./pathsConfig_CgNYYLVm.mjs";
|
|
3
|
-
import { i as workspaceRoot, r as repoRoot } from "./workspaceRoot_DVSUbYkd.mjs";
|
|
4
|
-
import { r as json, t as error } from "./apiUtils_B3BX89fM.mjs";
|
|
5
|
-
import { n as toTreeFiles, t as scanRoots } from "./vfsTreeScan_CKp7kMt9.mjs";
|
|
6
|
-
import { join } from "node:path";
|
|
7
|
-
//#region src/pages/api/vfs/tree.ts
|
|
8
|
-
var tree_exports = /* @__PURE__ */ __exportAll({ GET: () => GET });
|
|
9
|
-
/**
|
|
10
|
-
* VFS tree federation endpoint.
|
|
11
|
-
* Supports ?scope=<id> to return strictly bounded read-only subtrees (INV-WS-02).
|
|
12
|
-
*/
|
|
13
|
-
var GET = async (context) => {
|
|
14
|
-
try {
|
|
15
|
-
const root = repoRoot();
|
|
16
|
-
const projections = getWhitelistedDirectoryProjections();
|
|
17
|
-
const allowedScopes = projections.map((p) => p.id);
|
|
18
|
-
const scope = (context?.url?.searchParams ?? (context?.request ? new URL(context.request.url).searchParams : null))?.get("scope") ?? null;
|
|
19
|
-
if (scope && scope.trim() !== "") {
|
|
20
|
-
const projection = projections.find((p) => p.id === scope);
|
|
21
|
-
if (!projection) return error(`Invalid directory projection scope: '${scope}'. Allowed scopes: ${allowedScopes.join(", ")}`, 400);
|
|
22
|
-
const roots = [{
|
|
23
|
-
dir: projection.id === PATHS.paths.workspace_dirname ? workspaceRoot() : join(root, projection.path),
|
|
24
|
-
baseDir: root
|
|
25
|
-
}];
|
|
26
|
-
const files = toTreeFiles(scanRoots(roots)).map((file) => ({
|
|
27
|
-
...file,
|
|
28
|
-
scope: projection.id,
|
|
29
|
-
readOnly: true
|
|
30
|
-
}));
|
|
31
|
-
return json({
|
|
32
|
-
success: true,
|
|
33
|
-
scope: projection.id,
|
|
34
|
-
readOnly: true,
|
|
35
|
-
files,
|
|
36
|
-
scannedAt: Date.now()
|
|
37
|
-
}, 200, {
|
|
38
|
-
"Cache-Control": "no-cache, no-store, must-revalidate",
|
|
39
|
-
"Pragma": "no-cache",
|
|
40
|
-
"Expires": "0"
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
const roots = PATHS.vfs.scan_roots.map((scanRoot) => scanRoot === PATHS.paths.workspace_dirname ? {
|
|
44
|
-
dir: workspaceRoot(),
|
|
45
|
-
baseDir: root
|
|
46
|
-
} : {
|
|
47
|
-
dir: join(root, scanRoot),
|
|
48
|
-
baseDir: root
|
|
49
|
-
});
|
|
50
|
-
const files = toTreeFiles(scanRoots(roots)).map((file) => {
|
|
51
|
-
const matched = projections.find((p) => file.path.startsWith(p.path + "/") || file.path === p.path);
|
|
52
|
-
return {
|
|
53
|
-
...file,
|
|
54
|
-
scope: matched?.id || projections[0]?.id || PATHS.paths.assets_dirname,
|
|
55
|
-
readOnly: true
|
|
56
|
-
};
|
|
57
|
-
});
|
|
58
|
-
return json({
|
|
59
|
-
success: true,
|
|
60
|
-
readOnly: true,
|
|
61
|
-
files,
|
|
62
|
-
scannedAt: Date.now()
|
|
63
|
-
}, 200, {
|
|
64
|
-
"Cache-Control": "no-cache, no-store, must-revalidate",
|
|
65
|
-
"Pragma": "no-cache",
|
|
66
|
-
"Expires": "0"
|
|
67
|
-
});
|
|
68
|
-
} catch (err) {
|
|
69
|
-
return error(err instanceof Error ? err.message : "Failed to scan VFS", 500, { success: false });
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
//#endregion
|
|
73
|
-
//#region \0virtual:astro:page:src/pages/api/vfs/tree@_@ts
|
|
74
|
-
var page = () => tree_exports;
|
|
75
|
-
//#endregion
|
|
76
|
-
export { page };
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { t as __exportAll } from "./rolldown-runtime_8H4AJuhK.mjs";
|
|
2
|
-
import { MCardFileSystem } from "clm-kernel";
|
|
3
|
-
//#region src/services/vfs/vfsCore.ts
|
|
4
|
-
/**
|
|
5
|
-
* VFS Core — CAS Singleton (SSOT)
|
|
6
|
-
* Canonical Path: src/services/vfs/vfsCore.ts
|
|
7
|
-
* Deliverable: DEL-294-01 / DEL-294-04 (Sprint 294)
|
|
8
|
-
*
|
|
9
|
-
* Owns the single MCardFileSystem instance for the Studio Workbench
|
|
10
|
-
* (INV-294-03 SSOT Singleton Singularity). Every other VFS module
|
|
11
|
-
* consumes this instance via import; callers outside the VFS tree
|
|
12
|
-
* consume it via the mcardVfs facade re-export.
|
|
13
|
-
*/
|
|
14
|
-
var vfsCore_exports = /* @__PURE__ */ __exportAll({ studioMCardFs: () => studioMCardFs });
|
|
15
|
-
/**
|
|
16
|
-
* Universal Content-Addressable MCard Virtual Filesystem for Studio Workbench (INV-04, INV-05, INV-09).
|
|
17
|
-
* Instantiates the optimal storage backend across server (NodeSqliteBackend) and browser environments.
|
|
18
|
-
*/
|
|
19
|
-
var studioMCardFs = MCardFileSystem.createOptimal({ dbPath: ".clm/content_memory.db" });
|
|
20
|
-
//#endregion
|
|
21
|
-
export { vfsCore_exports as n, studioMCardFs as t };
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { t as PATHS } from "./pathsConfig_CgNYYLVm.mjs";
|
|
2
|
-
import { existsSync } from "node:fs";
|
|
3
|
-
import { dirname, join, resolve } from "node:path";
|
|
4
|
-
//#region src/server/workspaceRoot.ts
|
|
5
|
-
/**
|
|
6
|
-
* Installed-package root, when the CLI provides one (Program NP · INV-NP-05).
|
|
7
|
-
* An installed app must resolve its immutable assets from the package rather
|
|
8
|
-
* than guessing from the consumer's CWD. Returns null when unset or when the
|
|
9
|
-
* candidate does not carry the sentinel, so repo/tests keep prior behavior.
|
|
10
|
-
*/
|
|
11
|
-
function installedPackageRoot(config = PATHS) {
|
|
12
|
-
const envRoot = process.env.MCARD_PACKAGE_ROOT;
|
|
13
|
-
if (!envRoot) return null;
|
|
14
|
-
const resolved = resolve(envRoot);
|
|
15
|
-
const sentinelParts = config.paths.repo_root_sentinel.split("/").filter(Boolean);
|
|
16
|
-
return existsSync(join(resolved, ...sentinelParts)) ? resolved : null;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Locate the mcard-studio repository root reliably.
|
|
20
|
-
* The sentinel directory is `paths.repo_root_sentinel` (default `assets/clm`),
|
|
21
|
-
* so relocating the layout is a config change, not a code change (INV-PC-06).
|
|
22
|
-
* An explicit `MCARD_PACKAGE_ROOT` wins; otherwise the historical upward search
|
|
23
|
-
* from CWD is used.
|
|
24
|
-
*/
|
|
25
|
-
function repoRoot(config = PATHS) {
|
|
26
|
-
const installed = installedPackageRoot(config);
|
|
27
|
-
if (installed) return installed;
|
|
28
|
-
const sentinelParts = config.paths.repo_root_sentinel.split("/").filter(Boolean);
|
|
29
|
-
let cur = process.cwd();
|
|
30
|
-
while (cur !== "/" && dirname(cur) !== cur) {
|
|
31
|
-
if (existsSync(join(cur, "package.json")) && existsSync(join(cur, ...sentinelParts))) return cur;
|
|
32
|
-
cur = dirname(cur);
|
|
33
|
-
}
|
|
34
|
-
return process.cwd();
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Locate the active workspace root.
|
|
38
|
-
* `MCARD_WORKSPACE_ROOT` (env) still wins (absolute override); otherwise the
|
|
39
|
-
* configured `paths.workspace_dirname` under the repo root is used.
|
|
40
|
-
*/
|
|
41
|
-
function workspaceRoot(config = PATHS) {
|
|
42
|
-
const envRoot = process.env.MCARD_WORKSPACE_ROOT;
|
|
43
|
-
if (envRoot) return resolve(envRoot);
|
|
44
|
-
const base = process.env.MCARD_PROJECT_ROOT ? resolve(process.env.MCARD_PROJECT_ROOT) : repoRoot(config);
|
|
45
|
-
return join(base, config.paths.workspace_dirname);
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Security containment check (INV-PC-09): ensures the target path is strictly
|
|
49
|
-
* within any configured `vfs.scan_roots` directory or the resolved workspace root.
|
|
50
|
-
* This is a containment guard for the filesystem adapter — never an algebra input
|
|
51
|
-
* (INV-PC-10).
|
|
52
|
-
*/
|
|
53
|
-
function isPathAllowed(targetPath, rootDir = repoRoot(), config = PATHS) {
|
|
54
|
-
const resolved = resolve(rootDir, targetPath);
|
|
55
|
-
const allowedRoots = /* @__PURE__ */ new Set([resolve(workspaceRoot(config))]);
|
|
56
|
-
for (const scanRoot of config.vfs.scan_roots) allowedRoots.add(resolve(rootDir, scanRoot));
|
|
57
|
-
for (const root of allowedRoots) if (resolved === root || resolved.startsWith(root + "/")) return true;
|
|
58
|
-
return false;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Mutability containment check (Sprint EX-04, INV-EX-09):
|
|
62
|
-
* Ensures targetPath is strictly within the resolved workspaceRoot directory.
|
|
63
|
-
* Read-only projections (assets, computable_knowledge, public) reject writes with false.
|
|
64
|
-
*/
|
|
65
|
-
function isPathWritable(targetPath, rootDir = repoRoot(), config = PATHS) {
|
|
66
|
-
const resolved = resolve(rootDir, targetPath);
|
|
67
|
-
const wsRoot = resolve(workspaceRoot(config));
|
|
68
|
-
return resolved === wsRoot || resolved.startsWith(wsRoot + "/");
|
|
69
|
-
}
|
|
70
|
-
//#endregion
|
|
71
|
-
export { workspaceRoot as i, isPathWritable as n, repoRoot as r, isPathAllowed as t };
|
package/src/server/kernelHash.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { createRequire } from 'node:module';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Node ESM bridge to the published kernel's SHA-256 surface.
|
|
5
|
-
*
|
|
6
|
-
* `clm-kernel@0.0.3`'s ESM build implements `sha256HashSync` with a bare
|
|
7
|
-
* `require('node:crypto')`, which is undefined in ESM scope. The failure is
|
|
8
|
-
* swallowed and rethrown as "SHA-256 requires Node.js crypto module or Web
|
|
9
|
-
* Crypto API", so every `computeSha256` call in an ESM server process throws.
|
|
10
|
-
* The package's CJS build — declared under `exports.require` — has a working
|
|
11
|
-
* `require`, so load that entry point rather than forking the kernel's
|
|
12
|
-
* hashing logic.
|
|
13
|
-
*
|
|
14
|
-
* Remove this shim and import `computeSha256` from `clm-kernel/layer0`
|
|
15
|
-
* directly once the published ESM build is fixed.
|
|
16
|
-
*/
|
|
17
|
-
const require = createRequire(import.meta.url);
|
|
18
|
-
|
|
19
|
-
const kernelLayer0 = require('clm-kernel/layer0') as typeof import('clm-kernel/layer0');
|
|
20
|
-
|
|
21
|
-
/** Raw 64-character lowercase hex SHA-256 digest (published kernel implementation). */
|
|
22
|
-
export const computeSha256 = kernelLayer0.computeSha256;
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { MCard } from './mcard.ts';
|
|
2
|
-
import { SqliteNodeEngine } from './sqliteNodeEngine.ts';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Sovereign CardCollection
|
|
6
|
-
*
|
|
7
|
-
* Provides a high-level MCard & Handle collection API over a SqliteNodeEngine backend.
|
|
8
|
-
* Replaces mcard-js CardCollection with zero external dependencies.
|
|
9
|
-
*/
|
|
10
|
-
export class CardCollection {
|
|
11
|
-
private engine: SqliteNodeEngine;
|
|
12
|
-
|
|
13
|
-
constructor(engine: SqliteNodeEngine) {
|
|
14
|
-
this.engine = engine;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
getEngine(): SqliteNodeEngine {
|
|
18
|
-
return this.engine;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
async add(card: MCard): Promise<string> {
|
|
22
|
-
return this.engine.add(card);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
async get(hash: string): Promise<MCard | null> {
|
|
26
|
-
return this.engine.get(hash);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
async delete(hash: string): Promise<void> {
|
|
30
|
-
return this.engine.delete(hash);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
async count(): Promise<number> {
|
|
34
|
-
return this.engine.count();
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Store an MCard and register its handle in handle_registry.
|
|
39
|
-
* Supports flexible argument ordering (card, handle) or (handle, card).
|
|
40
|
-
*/
|
|
41
|
-
async addWithHandle(arg1: any, arg2: any): Promise<void> {
|
|
42
|
-
let card: MCard;
|
|
43
|
-
let handle: string;
|
|
44
|
-
|
|
45
|
-
if (arg1 && typeof arg1 === 'object' && ('hash' in arg1 || arg1 instanceof MCard)) {
|
|
46
|
-
card = arg1;
|
|
47
|
-
handle = String(arg2);
|
|
48
|
-
} else if (arg2 && typeof arg2 === 'object' && ('hash' in arg2 || arg2 instanceof MCard)) {
|
|
49
|
-
handle = String(arg1);
|
|
50
|
-
card = arg2;
|
|
51
|
-
} else if (typeof arg1 === 'string' && (typeof arg2 === 'string' || arg2 instanceof Uint8Array || Buffer.isBuffer(arg2))) {
|
|
52
|
-
handle = arg1;
|
|
53
|
-
card = await MCard.create(arg2);
|
|
54
|
-
} else {
|
|
55
|
-
card = await MCard.create(arg1);
|
|
56
|
-
handle = String(arg2);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
await this.engine.add(card);
|
|
60
|
-
await this.engine.registerHandle(handle, card.hash);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
async resolveHandle(handle: string): Promise<string | null> {
|
|
64
|
-
return this.engine.resolveHandle(handle);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
async updateHandle(handle: string, cardOrHash: MCard | string): Promise<string> {
|
|
68
|
-
return this.engine.updateHandle(handle, cardOrHash);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
async removeHandle(handle: string): Promise<void> {
|
|
72
|
-
return this.engine.removeHandle(handle);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
async getAllHandles(): Promise<{ handle: string; hash: string }[]> {
|
|
76
|
-
return this.engine.getAllHandles();
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
async getHandleHistory(handle: string): Promise<{ previousHash: string; changedAt: string }[]> {
|
|
80
|
-
return this.engine.getHandleHistory(handle);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
async getByHandle(handle: string): Promise<MCard | null> {
|
|
84
|
-
return this.engine.getByHandle(handle);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
async renameHandle(oldHandle: string, newHandle: string): Promise<void> {
|
|
88
|
-
return this.engine.renameHandle(oldHandle, newHandle);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
async deleteHistoryEntry(handle: string, previousHash: string): Promise<void> {
|
|
92
|
-
return this.engine.deleteHistoryEntry(handle, previousHash);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { computeSha256 } from '../kernelHash.ts';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Sovereign MCard Data Container (Layer 0 Monad)
|
|
5
|
-
* Backed by canonical clm-kernel cryptographic hashing and domain contracts.
|
|
6
|
-
*/
|
|
7
|
-
export class MCard {
|
|
8
|
-
readonly content: Uint8Array;
|
|
9
|
-
readonly hash: string;
|
|
10
|
-
readonly g_time: string;
|
|
11
|
-
readonly contentType: string;
|
|
12
|
-
readonly hashFunction: string;
|
|
13
|
-
|
|
14
|
-
constructor(
|
|
15
|
-
content: Uint8Array,
|
|
16
|
-
hash: string,
|
|
17
|
-
g_time: string,
|
|
18
|
-
contentType: string = 'text/plain',
|
|
19
|
-
hashFunction: string = 'sha256'
|
|
20
|
-
) {
|
|
21
|
-
this.content = content;
|
|
22
|
-
this.hash = hash;
|
|
23
|
-
this.g_time = g_time;
|
|
24
|
-
this.contentType = contentType;
|
|
25
|
-
this.hashFunction = hashFunction;
|
|
26
|
-
Object.freeze(this);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
static async create(
|
|
30
|
-
content: string | Uint8Array | Buffer | unknown,
|
|
31
|
-
hashAlgorithm: string = 'sha256'
|
|
32
|
-
): Promise<MCard> {
|
|
33
|
-
let bytes: Uint8Array;
|
|
34
|
-
let isText = false;
|
|
35
|
-
|
|
36
|
-
if (typeof content === 'string') {
|
|
37
|
-
bytes = new TextEncoder().encode(content);
|
|
38
|
-
isText = true;
|
|
39
|
-
} else if (Buffer.isBuffer(content)) {
|
|
40
|
-
bytes = new Uint8Array(content.buffer, content.byteOffset, content.byteLength);
|
|
41
|
-
} else if (content instanceof Uint8Array) {
|
|
42
|
-
bytes = content;
|
|
43
|
-
} else {
|
|
44
|
-
bytes = new TextEncoder().encode(String(content ?? ''));
|
|
45
|
-
isText = true;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const hash = computeSha256(bytes);
|
|
49
|
-
const g_time = new Date().toISOString();
|
|
50
|
-
const contentType = isText ? 'text/plain' : 'application/octet-stream';
|
|
51
|
-
|
|
52
|
-
return new MCard(bytes, hash, g_time, contentType, hashAlgorithm);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
static fromData(
|
|
56
|
-
content: Uint8Array | Buffer | string,
|
|
57
|
-
hash: string,
|
|
58
|
-
g_time: string
|
|
59
|
-
): MCard {
|
|
60
|
-
let bytes: Uint8Array;
|
|
61
|
-
if (typeof content === 'string') {
|
|
62
|
-
bytes = new TextEncoder().encode(content);
|
|
63
|
-
} else if (Buffer.isBuffer(content)) {
|
|
64
|
-
bytes = new Uint8Array(content.buffer, content.byteOffset, content.byteLength);
|
|
65
|
-
} else if (content instanceof Uint8Array) {
|
|
66
|
-
bytes = content;
|
|
67
|
-
} else {
|
|
68
|
-
bytes = new TextEncoder().encode(String(content ?? ''));
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return new MCard(bytes, hash, g_time);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
getContent(): Uint8Array {
|
|
75
|
-
return this.content;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
getContentAsText(): string {
|
|
79
|
-
return new TextDecoder().decode(this.content);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
toObject() {
|
|
83
|
-
return {
|
|
84
|
-
hash: this.hash,
|
|
85
|
-
content: this.getContentAsText(),
|
|
86
|
-
g_time: this.g_time,
|
|
87
|
-
contentType: this.contentType,
|
|
88
|
-
hashFunction: this.hashFunction
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
toJSON() {
|
|
93
|
-
return {
|
|
94
|
-
hash: this.hash,
|
|
95
|
-
content: this.getContentAsText(),
|
|
96
|
-
g_time: this.g_time
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
}
|