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.
- package/README.md +3 -0
- package/astro.config.mjs +46 -2
- package/bin/mcard-studio.mjs +1 -1
- package/cli/lib/runtimeContext.mjs +6 -3
- package/dist/client/_astro/{ChartAnalyticsViewlet.Cevj0EOs.js → ChartAnalyticsViewlet.CBW-JyA3.js} +1 -1
- package/dist/client/_astro/ClmPcardViewlet.cvKsR2ng.js +3 -0
- package/dist/client/_astro/D3GraphViewlet.8YEIrCGL.js +2 -0
- 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.CMJGCQN4.js +1 -0
- package/dist/client/_astro/{FaroVCardSpanInstrumenter.BIk2NhJY.js → FaroVCardSpanInstrumenter.ClIqZujq.js} +1 -1
- package/dist/client/_astro/{FontSpecimenViewlet.CpONhJh0.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.CHeNvX6L.js → ImageViewlet.Cs-u7-wt.js} +1 -1
- package/dist/client/_astro/{KatexFormulaViewlet.Cy_InWOK.js → KatexFormulaViewlet.0nOzV_qD.js} +1 -1
- package/dist/client/_astro/KoishiChatViewlet.DLsMmwdb.js +16 -0
- package/dist/client/_astro/MCardLibraryHarness.WBT9W10S.js +2 -0
- package/dist/client/_astro/{MarkdownViewlet.qoPlM-TZ.js → MarkdownViewlet.BIolkNXf.js} +25 -25
- package/dist/client/_astro/{MermaidDiagramViewlet.RnwDfQl6.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.D6HVdmrq.js → SchemaYamlViewlet.Bc7nkK4M.js} +1 -1
- 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
- package/dist/client/_astro/{Spatial3dViewlet.CCYBSSib.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.BxlWQ-JX.js → SvgViewlet.uGxvb06H.js} +1 -1
- package/dist/client/_astro/{TerminalView.DWZR-hUa.js → TerminalView.DP7G7E1m.js} +4 -4
- package/dist/client/_astro/{ThemeSettingsViewlet.Cb1r8fWw.js → ThemeSettingsViewlet.UaTHcGnF.js} +1 -1
- package/dist/client/_astro/{TikzDiagramViewlet.CqY7VTeP.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.LwKTA6h7.js → WelcomeViewport.CZ6RxGSw.js} +1 -1
- package/dist/client/_astro/{agentIdentityCredentialService.BtKVsl2C.js → agentIdentityCredentialService.BEtZzBlO.js} +5 -5
- package/dist/client/_astro/cardTypeDetector.C2HH5RnU.js +1 -0
- package/dist/client/_astro/disposable.BmlxZrDf.js +1 -0
- package/dist/client/_astro/{markdownService.D-tM2RYx.js → markdownService.CpuKl0vp.js} +1 -1
- package/dist/client/_astro/{mcardStore.BiAvqM-D.js → mcardStore.nSWnzeLg.js} +2 -2
- package/dist/client/_astro/mcardVfs.BSdys1Y7.js +3 -0
- package/dist/client/_astro/pathsConfig.CSBBSzwH.js +2 -0
- package/dist/client/_astro/polyfills.Bi7kO8cu.js +1 -0
- package/dist/client/_astro/rendererEventBus.DirFDmGw.js +1 -0
- package/dist/client/_astro/themeStore.BajxvCga.js +1 -0
- package/dist/client/_astro/{tikzCompiler.DFojjdxR.js → tikzCompiler.-fXMNQpz.js} +1 -1
- package/dist/client/_astro/{useMCardHydration.Co47OH3D.js → useMCardHydration.Bjj_N5Gv.js} +1 -1
- package/dist/client/_astro/vendor-ai.D6NcJ6lu.js +69 -0
- package/dist/client/_astro/vendor-clm-kernel.B0kxq3g4.js +108 -0
- package/dist/client/_astro/vfsHandles.D4Pq18pW.js +1 -0
- package/dist/client/_astro/vfsPersistence.DVrd1BZj.js +1 -0
- package/dist/client/_astro/vfsTransactions.DBNtFuRz.js +1 -0
- package/dist/client/_astro/{workspaceStore.CXakha4Y.js → workspaceStore.DUHW2YBc.js} +1 -1
- package/dist/client/js/buffer-polyfill.js +14 -0
- package/dist/server/chunks/{StudioLayout_D163irJ0.mjs → StudioLayout_taayQJ5b.mjs} +2 -2
- package/dist/server/chunks/{_.._ZXsz792-.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_DvPPUs9_.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_CkcgcI5V.mjs → ws-server-init_Cfft7U5u.mjs} +343 -298
- package/dist/server/entry.mjs +8 -4
- package/dist/server/entry2.mjs +67 -28
- package/dist/server/virtual_astro_middleware.mjs +2 -2
- package/package.json +2 -2
- package/public/js/buffer-polyfill.js +14 -0
- 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/layouts/StudioLayout.astro +1 -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/pages/index.astro +75 -0
- 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/inBrowserLlm/engines/litertEngine.ts +1 -1
- 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/ClmPcardViewlet.DW5Yft0E.js +0 -3
- package/dist/client/_astro/D3GraphViewlet.DAjPz1DP.js +0 -2
- package/dist/client/_astro/DockviewSpatialWorkbench.DyQjSoHd.js +0 -12
- package/dist/client/_astro/DocumentViewlets.Dm_GL3AL.js +0 -2
- package/dist/client/_astro/ExcalidrawWhiteboardViewlet.DrlW7B6G.js +0 -1
- package/dist/client/_astro/HeadMeta.astro_astro_type_script_index_0_lang.DGXU-3Lu.js +0 -1
- package/dist/client/_astro/KoishiChatViewlet.B0eDEMnT.js +0 -16
- package/dist/client/_astro/MCardLibraryHarness.CUJLJFBt.js +0 -2
- package/dist/client/_astro/PCardRendererBridge.BnyaE05I.js +0 -1
- package/dist/client/_astro/RendererPCardRegistry.CLr4j1Ub.js +0 -1
- package/dist/client/_astro/StudioWorkbench.CF0SOYwy.js +0 -7
- package/dist/client/_astro/VideoPlayerViewlet.DoSYmmoQ.js +0 -1
- package/dist/client/_astro/WebappZenViewlet.CQW50OhX.js +0 -1
- package/dist/client/_astro/cardTypeDetector.C9kGObMh.js +0 -1
- package/dist/client/_astro/disposable.66apX1Q2.js +0 -1
- package/dist/client/_astro/empty.DOwCrGXH.js +0 -1
- package/dist/client/_astro/mcardVfs.Bj-RA0p7.js +0 -2
- package/dist/client/_astro/path.CR60mj9W.js +0 -1
- package/dist/client/_astro/pathsConfig.D0hV34p7.js +0 -2
- package/dist/client/_astro/polyfills.DcBkS56X.js +0 -1
- package/dist/client/_astro/rendererEventBus.CyFnSRLk.js +0 -1
- package/dist/client/_astro/themeStore.zUMFLo3Q.js +0 -1
- package/dist/client/_astro/vendor-ai.CZe7UVVK.js +0 -69
- package/dist/client/_astro/vfsHandles.B-nczBRy.js +0 -1
- package/dist/client/_astro/vfsPersistence.D6zRzVML.js +0 -1
- package/dist/client/_astro/vfsTransactions.04mkEHxD.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
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/core/projection/views.ts
|
|
3
|
+
*
|
|
4
|
+
* Pure projection view-models for History, Residency, Hash Pill and Lineage (DoD-08-3, DoD-08-6).
|
|
5
|
+
* Computes presentation models from immutable kernel records and transitions.
|
|
6
|
+
*
|
|
7
|
+
* Strictly pure: zero imports from edge, membrane, ui, Node built-ins, or DOM.
|
|
8
|
+
* Contract D budget: <= 250 LOC.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import {
|
|
12
|
+
parseGTime,
|
|
13
|
+
verifyRecord,
|
|
14
|
+
verifyAttribution,
|
|
15
|
+
authorOf,
|
|
16
|
+
qualify,
|
|
17
|
+
type MCardRecord,
|
|
18
|
+
type VerifyRecordOutcome,
|
|
19
|
+
} from 'clm-kernel';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The kernel's record classification, verbatim (`VerifyRecordOutcome`).
|
|
23
|
+
*
|
|
24
|
+
* A legacy row is never collapsed to an algorithm: the kernel reports whether recomputation
|
|
25
|
+
* classified it, found nothing, or found two candidates. Studio renders that verdict.
|
|
26
|
+
*/
|
|
27
|
+
export type RecordClassification =
|
|
28
|
+
| 'declared-ok'
|
|
29
|
+
| 'declared-mismatch'
|
|
30
|
+
| 'legacy-classified'
|
|
31
|
+
| 'legacy-unclassified'
|
|
32
|
+
| 'legacy-ambiguous'
|
|
33
|
+
| 'malformed';
|
|
34
|
+
|
|
35
|
+
export interface HashPillViewModel {
|
|
36
|
+
/** Badge label: the record's declared algorithm, `legacy`, or `malformed`. Never a default. */
|
|
37
|
+
readonly algorithm: string;
|
|
38
|
+
/** The kernel's classification, shown as-is so the verdict is never inferred. */
|
|
39
|
+
readonly classification: RecordClassification;
|
|
40
|
+
/** For `legacy-classified` only: the algorithm recomputation established. Evidence, not a declaration. */
|
|
41
|
+
readonly recomputedAlgorithm: string | null;
|
|
42
|
+
readonly qualifiedHash: string;
|
|
43
|
+
readonly shortHash: string;
|
|
44
|
+
readonly permalink: string;
|
|
45
|
+
readonly isLegacyOrMalformed: boolean;
|
|
46
|
+
readonly rowAuthor: string | null;
|
|
47
|
+
readonly actAuthor: string | null;
|
|
48
|
+
readonly signatureStatus: 'signed-ok' | 'signed-bad' | 'unsigned' | 'unresolved';
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface ResidencyStateViewModel {
|
|
52
|
+
readonly browser: 'present' | 'fetch-needed';
|
|
53
|
+
readonly server: 'committed' | 'not';
|
|
54
|
+
readonly replicas: ReadonlyMap<string, { readonly status: 'verified' | 'pending' | 'none'; readonly verifiedAt?: string }>;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface LineageAnchorViewModel {
|
|
58
|
+
readonly hash: string;
|
|
59
|
+
readonly timestamp: string;
|
|
60
|
+
readonly actor: string | null;
|
|
61
|
+
readonly signatureStatus: string;
|
|
62
|
+
readonly reason: string;
|
|
63
|
+
readonly prunedCount: number;
|
|
64
|
+
readonly archiveRef: string;
|
|
65
|
+
readonly successors?: ReadonlyArray<{ readonly old: string; readonly next: string }>;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface LineageResolutionResult {
|
|
69
|
+
readonly location: 'working' | 'archive' | 'not-found';
|
|
70
|
+
readonly containerRef?: string;
|
|
71
|
+
readonly anchorHash?: string;
|
|
72
|
+
readonly isReimported?: boolean;
|
|
73
|
+
readonly archivedOriginal?: string;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Computes the view model for the Hash Pill from record and optional transition author.
|
|
78
|
+
* Strictly derives the algorithm from the record's own g_time, never from ambient config.
|
|
79
|
+
*/
|
|
80
|
+
export function computeHashPill(record: MCardRecord, transitionAuthor?: string): HashPillViewModel {
|
|
81
|
+
const outcome: VerifyRecordOutcome = verifyRecord(record);
|
|
82
|
+
const status = outcome.status;
|
|
83
|
+
const isLegacy = status === 'legacy-classified' || status === 'legacy-unclassified' || status === 'legacy-ambiguous';
|
|
84
|
+
const isMalformed = status === 'malformed' || status === 'declared-mismatch';
|
|
85
|
+
|
|
86
|
+
// A declared record shows the algorithm its own g_time names. A legacy row shows its
|
|
87
|
+
// classification — never the ambient default, which would make an unclassified row
|
|
88
|
+
// indistinguishable from a verified one (DoD-08-6, DoD-00-20).
|
|
89
|
+
const algorithm = status === 'declared-ok'
|
|
90
|
+
? outcome.algorithm
|
|
91
|
+
: isLegacy
|
|
92
|
+
? 'legacy'
|
|
93
|
+
: 'malformed';
|
|
94
|
+
const recomputedAlgorithm = status === 'legacy-classified' ? outcome.algorithm : null;
|
|
95
|
+
|
|
96
|
+
const rawHex = record.hash.includes(':') ? record.hash.split(':')[1]!.toLowerCase() : record.hash.toLowerCase();
|
|
97
|
+
const qualifiedHash = status === 'declared-ok' || status === 'legacy-classified'
|
|
98
|
+
? outcome.qualifiedHash
|
|
99
|
+
: `${algorithm}:${rawHex}`;
|
|
100
|
+
const shortHex = rawHex.slice(0, 8);
|
|
101
|
+
const shortHash = `${algorithm}:${shortHex}`;
|
|
102
|
+
const permalink = `mcard://hash/${qualifiedHash}`;
|
|
103
|
+
|
|
104
|
+
const rowAuthor = authorOf(record.gTime) || null;
|
|
105
|
+
const actAuthor = transitionAuthor || null;
|
|
106
|
+
|
|
107
|
+
const attr = verifyAttribution(record);
|
|
108
|
+
let signatureStatus: 'signed-ok' | 'signed-bad' | 'unsigned' | 'unresolved' = 'unsigned';
|
|
109
|
+
if (attr.signed) {
|
|
110
|
+
signatureStatus = attr.valid ? 'signed-ok' : 'signed-bad';
|
|
111
|
+
} else if (attr.reason?.includes('unresolved')) {
|
|
112
|
+
signatureStatus = 'unresolved';
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return {
|
|
116
|
+
algorithm,
|
|
117
|
+
classification: status,
|
|
118
|
+
recomputedAlgorithm,
|
|
119
|
+
qualifiedHash,
|
|
120
|
+
shortHash,
|
|
121
|
+
permalink,
|
|
122
|
+
isLegacyOrMalformed: isLegacy || isMalformed,
|
|
123
|
+
rowAuthor,
|
|
124
|
+
actAuthor,
|
|
125
|
+
signatureStatus,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Computes the Residency view model from driver query observations.
|
|
131
|
+
*/
|
|
132
|
+
export function computeResidency(options: {
|
|
133
|
+
readonly browserHas?: boolean;
|
|
134
|
+
readonly serverCommitted?: boolean;
|
|
135
|
+
readonly receipts?: ReadonlyArray<{ readonly driver: string; readonly ref: string; readonly verifiedAt: string }>;
|
|
136
|
+
readonly configuredDrivers?: readonly string[];
|
|
137
|
+
}): ResidencyStateViewModel {
|
|
138
|
+
const browser: 'present' | 'fetch-needed' = options.browserHas ? 'present' : 'fetch-needed';
|
|
139
|
+
const server: 'committed' | 'not' = options.serverCommitted !== false ? 'committed' : 'not';
|
|
140
|
+
|
|
141
|
+
const replicaMap = new Map<string, { status: 'verified' | 'pending' | 'none'; verifiedAt?: string }>();
|
|
142
|
+
|
|
143
|
+
// Add all known receipts
|
|
144
|
+
for (const r of options.receipts || []) {
|
|
145
|
+
replicaMap.set(r.driver, {
|
|
146
|
+
status: 'verified',
|
|
147
|
+
verifiedAt: r.verifiedAt,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Any configured driver with no receipt is none/pending, NEVER verified (INV-CAS-14)
|
|
152
|
+
for (const driver of options.configuredDrivers || []) {
|
|
153
|
+
if (!replicaMap.has(driver)) {
|
|
154
|
+
replicaMap.set(driver, { status: 'none' });
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return {
|
|
159
|
+
browser,
|
|
160
|
+
server,
|
|
161
|
+
replicas: replicaMap,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Parses and extracts anchor chain from working records in reverse chronological order.
|
|
167
|
+
*/
|
|
168
|
+
export function extractLineageAnchors(records: readonly MCardRecord[]): LineageAnchorViewModel[] {
|
|
169
|
+
const anchors: LineageAnchorViewModel[] = [];
|
|
170
|
+
for (const rec of records) {
|
|
171
|
+
try {
|
|
172
|
+
const text = new TextDecoder('utf-8', { fatal: true }).decode(rec.content);
|
|
173
|
+
if (text.includes('"lineage-anchor"')) {
|
|
174
|
+
const payload = JSON.parse(text);
|
|
175
|
+
if (payload.kind === 'lineage-anchor' && payload.archive) {
|
|
176
|
+
const attr = verifyAttribution(rec);
|
|
177
|
+
const successors = Array.isArray(payload.successors)
|
|
178
|
+
? payload.successors.map((s: [string, string]) => ({ old: s[0], next: s[1] }))
|
|
179
|
+
: undefined;
|
|
180
|
+
|
|
181
|
+
anchors.push({
|
|
182
|
+
hash: rec.hash,
|
|
183
|
+
timestamp: payload.timestamp || rec.gTime || '',
|
|
184
|
+
actor: payload.actor || authorOf(rec.gTime) || null,
|
|
185
|
+
signatureStatus: attr.signed ? (attr.valid ? 'signed-ok' : 'signed-bad') : 'unsigned',
|
|
186
|
+
reason: payload.reason || 'prune',
|
|
187
|
+
prunedCount: Array.isArray(payload.pruned) ? payload.pruned.length : 0,
|
|
188
|
+
archiveRef: payload.archive,
|
|
189
|
+
successors,
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
} catch {}
|
|
194
|
+
}
|
|
195
|
+
return anchors.reverse();
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Searches for a hash in working tape or historical archive anchors.
|
|
200
|
+
*/
|
|
201
|
+
export function findHashInLineage(
|
|
202
|
+
targetRefOrHex: string,
|
|
203
|
+
workingRecords: readonly MCardRecord[],
|
|
204
|
+
anchors: readonly LineageAnchorViewModel[]
|
|
205
|
+
): LineageResolutionResult {
|
|
206
|
+
const rawHex = targetRefOrHex.includes(':') ? targetRefOrHex.split(':')[1]!.toLowerCase() : targetRefOrHex.toLowerCase();
|
|
207
|
+
|
|
208
|
+
// 1. Check working records
|
|
209
|
+
const inWorking = workingRecords.some((r) => {
|
|
210
|
+
const rHex = r.hash.includes(':') ? r.hash.split(':')[1]!.toLowerCase() : r.hash.toLowerCase();
|
|
211
|
+
return rHex === rawHex;
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
if (inWorking) {
|
|
215
|
+
return { location: 'working' };
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// 2. Check anchors
|
|
219
|
+
for (const anchor of anchors) {
|
|
220
|
+
// Check successors (reimported legacy records)
|
|
221
|
+
if (anchor.successors) {
|
|
222
|
+
const matchSuccessor = anchor.successors.find(
|
|
223
|
+
(s) => s.next.toLowerCase().includes(rawHex) || s.old.toLowerCase().includes(rawHex)
|
|
224
|
+
);
|
|
225
|
+
if (matchSuccessor) {
|
|
226
|
+
return {
|
|
227
|
+
location: 'archive',
|
|
228
|
+
containerRef: anchor.archiveRef,
|
|
229
|
+
anchorHash: anchor.hash,
|
|
230
|
+
isReimported: true,
|
|
231
|
+
archivedOriginal: matchSuccessor.old,
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (anchor.archiveRef.toLowerCase().includes(rawHex)) {
|
|
237
|
+
return { location: 'archive', containerRef: anchor.archiveRef, anchorHash: anchor.hash };
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
return { location: 'not-found' };
|
|
242
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/core/refinement/designMetrics.ts
|
|
3
|
+
* Suh Axiomatic Design coupling and Leinster–Cobbold diversity, migrated from the
|
|
4
|
+
* Least-Action Navigator's documented formulas (SMR-11 · DoD-SMR-11-01).
|
|
5
|
+
*
|
|
6
|
+
* Suh: {FR} = [A]{DP}, information I = −log₂(P)
|
|
7
|
+
* Leinster: q ≠ 1: D_q = (Σ_i p_i (Σ_j s_ij p_j)^(q−1))^(1/(1−q))
|
|
8
|
+
* q = 1: D_1 = exp(−Σ_i p_i ln(Σ_j s_ij p_j))
|
|
9
|
+
*
|
|
10
|
+
* Re-exported by `lagrangianEngine.ts`, which the sprint names as the engine module;
|
|
11
|
+
* the split keeps each file inside its Contract D budget.
|
|
12
|
+
*
|
|
13
|
+
* PURE by construction (INV-FM-02). Contract D budget: <= 200 LOC.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
const round4 = (value: number) => Number(value.toFixed(4));
|
|
17
|
+
const clamp01 = (value: number) => Math.min(1, Math.max(0, value));
|
|
18
|
+
|
|
19
|
+
/** Suh information axiom: I = −log₂(P) bits. An impossible requirement is infinite. */
|
|
20
|
+
export function suhInformation(probability: number): number {
|
|
21
|
+
const p = clamp01(probability);
|
|
22
|
+
if (p <= 0) return Number.POSITIVE_INFINITY;
|
|
23
|
+
return round4(-Math.log2(p));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type SuhStructure = 'uncoupled' | 'decoupled' | 'coupled';
|
|
27
|
+
|
|
28
|
+
export interface SuhCouplingReport {
|
|
29
|
+
readonly functionalRequirements: number;
|
|
30
|
+
readonly designParameters: number;
|
|
31
|
+
readonly offDiagonal: number;
|
|
32
|
+
readonly couplingRatio: number;
|
|
33
|
+
readonly structure: SuhStructure;
|
|
34
|
+
/** Information content of satisfying the independence axiom, I = −log₂(1 − ratio). */
|
|
35
|
+
readonly information: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Suh Axiomatic Design: `{FR} = [A]{DP}`. A diagonal matrix is uncoupled, a
|
|
40
|
+
* triangular one is decoupled, anything else is coupled; the coupling ratio is the
|
|
41
|
+
* fraction of populated entries that sit off the diagonal.
|
|
42
|
+
*/
|
|
43
|
+
export function suhCoupling(matrix: readonly (readonly number[])[]): SuhCouplingReport {
|
|
44
|
+
const rows = matrix.length;
|
|
45
|
+
const cols = rows > 0 ? matrix[0].length : 0;
|
|
46
|
+
let offDiagonal = 0;
|
|
47
|
+
let populated = 0;
|
|
48
|
+
let upperOnly = true;
|
|
49
|
+
let lowerOnly = true;
|
|
50
|
+
|
|
51
|
+
for (let i = 0; i < rows; i += 1) {
|
|
52
|
+
for (let j = 0; j < cols; j += 1) {
|
|
53
|
+
if ((matrix[i][j] ?? 0) === 0) continue;
|
|
54
|
+
populated += 1;
|
|
55
|
+
if (i === j) continue;
|
|
56
|
+
offDiagonal += 1;
|
|
57
|
+
if (j < i) upperOnly = false;
|
|
58
|
+
if (j > i) lowerOnly = false;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const couplingRatio = populated === 0 ? 0 : offDiagonal / populated;
|
|
63
|
+
const structure: SuhStructure =
|
|
64
|
+
offDiagonal === 0 ? 'uncoupled' : upperOnly || lowerOnly ? 'decoupled' : 'coupled';
|
|
65
|
+
return {
|
|
66
|
+
functionalRequirements: rows,
|
|
67
|
+
designParameters: cols,
|
|
68
|
+
offDiagonal,
|
|
69
|
+
couplingRatio: round4(couplingRatio),
|
|
70
|
+
structure,
|
|
71
|
+
information: suhInformation(1 - couplingRatio),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Leinster–Cobbold diversity of order q. With the identity similarity this reduces
|
|
77
|
+
* to the Hill number, so a uniform distribution over n items yields D_q = n — the
|
|
78
|
+
* property the unit test asserts.
|
|
79
|
+
*/
|
|
80
|
+
export function leinsterDiversity(
|
|
81
|
+
probabilities: readonly number[],
|
|
82
|
+
similarity?: readonly (readonly number[])[],
|
|
83
|
+
q = 1,
|
|
84
|
+
): number {
|
|
85
|
+
const n = probabilities.length;
|
|
86
|
+
if (n === 0) return 0;
|
|
87
|
+
const s = similarity ?? probabilities.map((_, i) => probabilities.map((__, j) => (i === j ? 1 : 0)));
|
|
88
|
+
const sums = probabilities.map((_, i) =>
|
|
89
|
+
probabilities.reduce((total, p, j) => total + (s[i]?.[j] ?? 0) * p, 0),
|
|
90
|
+
);
|
|
91
|
+
if (sums.every((value) => value <= 0)) return 0;
|
|
92
|
+
|
|
93
|
+
if (Math.abs(q - 1) < 1e-9) {
|
|
94
|
+
const exponent = probabilities.reduce((total, p, i) => total + (p > 0 ? p * Math.log(sums[i]) : 0), 0);
|
|
95
|
+
return round4(Math.exp(-exponent));
|
|
96
|
+
}
|
|
97
|
+
const inner = probabilities.reduce((total, p, i) => total + p * Math.pow(sums[i], q - 1), 0);
|
|
98
|
+
return round4(Math.pow(inner, 1 / (1 - q)));
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** The estate's signal-to-noise transform of a diversity value: 1 − (1 − s)^D. */
|
|
102
|
+
export function leinsterSignalToNoise(diversity: number, similarity = 0.5): number {
|
|
103
|
+
return round4(1 - Math.pow(1 - similarity, diversity));
|
|
104
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/core/refinement/fibrationProjector.ts
|
|
3
|
+
* Base-category → fiber-category projection and least-action trajectories
|
|
4
|
+
* (SMR-11 · DoD-SMR-11-01), migrated from the Fibration Dashboard's assessment
|
|
5
|
+
* model (`LandingPage/js/observability/fibration-dashboard.js`).
|
|
6
|
+
*
|
|
7
|
+
* The base category is the deployment unit's name; a fiber sits over it at one
|
|
8
|
+
* coordinate τ (platform, form factor, orientation, locale, display mode, power
|
|
9
|
+
* mode, adapter). Refinement is a trajectory through those fibers: the engine orders
|
|
10
|
+
* revisions by the Lagrangian and reports the direction of each step.
|
|
11
|
+
*
|
|
12
|
+
* PURE by construction (INV-FM-02): no DOM, no I/O, no ambient reads.
|
|
13
|
+
* Contract D budget: <= 180 LOC.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import type { LagrangianRegime } from './lagrangianEngine';
|
|
17
|
+
|
|
18
|
+
/** One point of the fiber base: the deployment coordinate τ. */
|
|
19
|
+
export interface FiberCoordinate {
|
|
20
|
+
readonly platform?: string;
|
|
21
|
+
readonly form_factor?: string;
|
|
22
|
+
readonly orientation?: string;
|
|
23
|
+
readonly locale?: string;
|
|
24
|
+
readonly display_mode?: string;
|
|
25
|
+
readonly power_mode?: string;
|
|
26
|
+
readonly adapter?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface AssessmentUnit {
|
|
30
|
+
readonly unit: string;
|
|
31
|
+
readonly tau?: FiberCoordinate;
|
|
32
|
+
readonly payload_bytes?: number;
|
|
33
|
+
readonly within_budget?: boolean;
|
|
34
|
+
readonly S_T: number;
|
|
35
|
+
readonly H_T: number;
|
|
36
|
+
readonly lagrangian: number;
|
|
37
|
+
readonly regime: LagrangianRegime;
|
|
38
|
+
readonly functionality_coverage?: number;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface FiberPoint {
|
|
42
|
+
readonly coordinate: string;
|
|
43
|
+
readonly unit: string;
|
|
44
|
+
readonly lagrangian: number;
|
|
45
|
+
readonly regime: LagrangianRegime;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface FibrationProjection {
|
|
49
|
+
readonly base: string;
|
|
50
|
+
readonly fiberCount: number;
|
|
51
|
+
readonly fibers: readonly FiberPoint[];
|
|
52
|
+
readonly best: FiberPoint | null;
|
|
53
|
+
readonly worst: FiberPoint | null;
|
|
54
|
+
/** Spread between the best and worst fiber: how much the coordinate matters. */
|
|
55
|
+
readonly spread: number;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Renders a coordinate as a stable key, in a fixed field order. */
|
|
59
|
+
export function coordinateKey(tau: FiberCoordinate = {}): string {
|
|
60
|
+
return [tau.platform, tau.form_factor, tau.orientation, tau.locale, tau.display_mode, tau.power_mode, tau.adapter]
|
|
61
|
+
.map((value) => value ?? '*')
|
|
62
|
+
.join('/');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Projects every unit sitting over one base onto its fiber coordinate. */
|
|
66
|
+
export function projectFibration(base: string, units: readonly AssessmentUnit[]): FibrationProjection {
|
|
67
|
+
const over = units.filter((unit) => unit.unit === base);
|
|
68
|
+
const fibers: FiberPoint[] = over
|
|
69
|
+
.map((unit) => ({
|
|
70
|
+
coordinate: coordinateKey(unit.tau),
|
|
71
|
+
unit: unit.unit,
|
|
72
|
+
lagrangian: unit.lagrangian,
|
|
73
|
+
regime: unit.regime,
|
|
74
|
+
}))
|
|
75
|
+
.sort((a, b) => b.lagrangian - a.lagrangian);
|
|
76
|
+
|
|
77
|
+
const best = fibers[0] ?? null;
|
|
78
|
+
const worst = fibers[fibers.length - 1] ?? null;
|
|
79
|
+
return {
|
|
80
|
+
base,
|
|
81
|
+
fiberCount: fibers.length,
|
|
82
|
+
fibers,
|
|
83
|
+
best,
|
|
84
|
+
worst,
|
|
85
|
+
spread: best && worst ? Number((best.lagrangian - worst.lagrangian).toFixed(4)) : 0,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export type RefinementDirection = 'refine' | 'degrade' | 'neutral';
|
|
90
|
+
|
|
91
|
+
export interface RefinementStep {
|
|
92
|
+
readonly from: string;
|
|
93
|
+
readonly to: string;
|
|
94
|
+
readonly deltaLagrangian: number;
|
|
95
|
+
readonly direction: RefinementDirection;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export interface RefinementTrajectory {
|
|
99
|
+
readonly handle: string;
|
|
100
|
+
readonly steps: readonly RefinementStep[];
|
|
101
|
+
readonly netLagrangian: number;
|
|
102
|
+
readonly direction: RefinementDirection;
|
|
103
|
+
readonly imaginaryAction: boolean;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Trajectory across `handle_history`: revisions are ordered oldest-first and each
|
|
108
|
+
* consecutive pair yields a step. A trajectory whose net Lagrangian is negative has
|
|
109
|
+
* imaginary action distance — the estate's pruning signal.
|
|
110
|
+
*/
|
|
111
|
+
export function refinementTrajectory(
|
|
112
|
+
handle: string,
|
|
113
|
+
revisions: readonly { readonly hash: string; readonly lagrangian: number; readonly changedAt?: string }[],
|
|
114
|
+
): RefinementTrajectory {
|
|
115
|
+
const ordered = [...revisions].sort((a, b) => String(a.changedAt ?? '').localeCompare(String(b.changedAt ?? '')));
|
|
116
|
+
const steps: RefinementStep[] = [];
|
|
117
|
+
for (let i = 1; i < ordered.length; i += 1) {
|
|
118
|
+
const delta = Number((ordered[i].lagrangian - ordered[i - 1].lagrangian).toFixed(4));
|
|
119
|
+
steps.push({
|
|
120
|
+
from: ordered[i - 1].hash,
|
|
121
|
+
to: ordered[i].hash,
|
|
122
|
+
deltaLagrangian: delta,
|
|
123
|
+
direction: delta > 0 ? 'refine' : delta < 0 ? 'degrade' : 'neutral',
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
const net = ordered.length > 1 ? Number((ordered[ordered.length - 1].lagrangian - ordered[0].lagrangian).toFixed(4)) : 0;
|
|
127
|
+
return {
|
|
128
|
+
handle,
|
|
129
|
+
steps,
|
|
130
|
+
netLagrangian: net,
|
|
131
|
+
direction: net > 0 ? 'refine' : net < 0 ? 'degrade' : 'neutral',
|
|
132
|
+
imaginaryAction: net < 0,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Least-action path: the greedy ordering that always moves to the highest
|
|
138
|
+
* Lagrangian available, used by the Navigator's recommendation list.
|
|
139
|
+
*/
|
|
140
|
+
export function leastActionPath(units: readonly AssessmentUnit[]): string[] {
|
|
141
|
+
return [...units].sort((a, b) => b.lagrangian - a.lagrangian).map((unit) => unit.unit);
|
|
142
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/core/refinement/lagrangianEngine.ts
|
|
3
|
+
* Software Lagrangian, Suh Axiomatic Design coupling, and Leinster diversity —
|
|
4
|
+
* migrated from `LandingPage/js/observability/lagrangian.js` (CDO-13) and the
|
|
5
|
+
* Least-Action Navigator, as pure zero-DOM calculators (SMR-11 · DoD-SMR-11-01).
|
|
6
|
+
*
|
|
7
|
+
* ℒ(u, τ) = S_T(u, τ) − H_T(u, τ)
|
|
8
|
+
* S_T = Epiplexity (learnable structural invariants, capability)
|
|
9
|
+
* H_T = Axiomatic Entropy (coupling friction, residual entropy, debt)
|
|
10
|
+
*
|
|
11
|
+
* The original module wrote an assessment artifact to disk; that write is I/O and
|
|
12
|
+
* therefore excluded from core — `buildAssessmentArtifact` returns the record and a
|
|
13
|
+
* caller persists it.
|
|
14
|
+
*
|
|
15
|
+
* PURE by construction (INV-FM-02): no DOM, no I/O, no ambient reads.
|
|
16
|
+
* Contract D budget: <= 200 LOC.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
export interface LagrangianWeights {
|
|
20
|
+
readonly epiplexity: {
|
|
21
|
+
readonly w1_invariant_coverage: number;
|
|
22
|
+
readonly w2_lattice_pass_rate: number;
|
|
23
|
+
readonly w3_adapter_coverage: number;
|
|
24
|
+
readonly w4_witness_count: number;
|
|
25
|
+
readonly w5_evidence_level: number;
|
|
26
|
+
};
|
|
27
|
+
readonly entropy: {
|
|
28
|
+
readonly v1_budget_breach_ratio: number;
|
|
29
|
+
readonly v2_residual_entropy: number;
|
|
30
|
+
readonly v3_uncovered_lattice_fraction: number;
|
|
31
|
+
readonly v4_visual_drift_ratio: number;
|
|
32
|
+
readonly v5_adapter_overhead: number;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Weights ported unchanged from `lagrangian.js`. */
|
|
37
|
+
export const DEFAULT_WEIGHTS: LagrangianWeights = {
|
|
38
|
+
epiplexity: {
|
|
39
|
+
w1_invariant_coverage: 0.25,
|
|
40
|
+
w2_lattice_pass_rate: 0.25,
|
|
41
|
+
w3_adapter_coverage: 0.2,
|
|
42
|
+
w4_witness_count: 0.15,
|
|
43
|
+
w5_evidence_level: 0.15,
|
|
44
|
+
},
|
|
45
|
+
entropy: {
|
|
46
|
+
v1_budget_breach_ratio: 0.3,
|
|
47
|
+
v2_residual_entropy: 0.3,
|
|
48
|
+
v3_uncovered_lattice_fraction: 0.15,
|
|
49
|
+
v4_visual_drift_ratio: 0.15,
|
|
50
|
+
v5_adapter_overhead: 0.1,
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export interface UnitMetrics {
|
|
55
|
+
readonly functionality?: {
|
|
56
|
+
readonly invariant_coverage?: number;
|
|
57
|
+
readonly lattice_pass_rate?: number;
|
|
58
|
+
readonly adapter_coverage?: number;
|
|
59
|
+
readonly witness_count?: number;
|
|
60
|
+
readonly evidence_level_score?: number;
|
|
61
|
+
};
|
|
62
|
+
readonly payload?: { readonly total_bytes?: number; readonly budget_breach_ratio?: number; readonly within_budget?: boolean };
|
|
63
|
+
readonly performance?: { readonly residual_entropy?: number; readonly adapter_overhead_kb?: number; readonly lcp_ms?: number };
|
|
64
|
+
readonly visual?: { readonly drift_ratio?: number };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export type LagrangianRegime = 'geodesic' | 'marginal' | 'pruning';
|
|
68
|
+
|
|
69
|
+
export interface LagrangianScore {
|
|
70
|
+
readonly S_T: number;
|
|
71
|
+
readonly H_T: number;
|
|
72
|
+
readonly lagrangian: number;
|
|
73
|
+
readonly regime: LagrangianRegime;
|
|
74
|
+
readonly is_real_action: boolean;
|
|
75
|
+
readonly dominant_entropy_contributor: string;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const round4 = (value: number) => Number(value.toFixed(4));
|
|
79
|
+
const clamp01 = (value: number) => Math.min(1, Math.max(0, value));
|
|
80
|
+
|
|
81
|
+
/** ℒ = S_T − H_T with the estate's five-term Epiplexity and Entropy weights. */
|
|
82
|
+
export function computeLagrangian(
|
|
83
|
+
metrics: UnitMetrics = {},
|
|
84
|
+
weights: LagrangianWeights = DEFAULT_WEIGHTS,
|
|
85
|
+
): LagrangianScore {
|
|
86
|
+
const ep = weights.epiplexity;
|
|
87
|
+
const en = weights.entropy;
|
|
88
|
+
|
|
89
|
+
const invariantCoverage = metrics.functionality?.invariant_coverage ?? 1.0;
|
|
90
|
+
const latticePassRate = metrics.functionality?.lattice_pass_rate ?? 1.0;
|
|
91
|
+
const adapterCoverage = metrics.functionality?.adapter_coverage ?? 1.0;
|
|
92
|
+
const witnessCount = metrics.functionality?.witness_count ?? 6;
|
|
93
|
+
const evidenceLevel = metrics.functionality?.evidence_level_score ?? 0.75;
|
|
94
|
+
const normalizedWitness = Math.min(1.0, Math.log2(1 + witnessCount) / 4);
|
|
95
|
+
|
|
96
|
+
const S_T =
|
|
97
|
+
ep.w1_invariant_coverage * invariantCoverage +
|
|
98
|
+
ep.w2_lattice_pass_rate * latticePassRate +
|
|
99
|
+
ep.w3_adapter_coverage * adapterCoverage +
|
|
100
|
+
ep.w4_witness_count * normalizedWitness +
|
|
101
|
+
ep.w5_evidence_level * evidenceLevel;
|
|
102
|
+
|
|
103
|
+
const breachRatio = clamp01(metrics.payload?.budget_breach_ratio ?? 0);
|
|
104
|
+
const residualEntropy = clamp01(metrics.performance?.residual_entropy ?? 0);
|
|
105
|
+
const uncoveredLattice = 1.0 - latticePassRate;
|
|
106
|
+
const visualDrift = clamp01(metrics.visual?.drift_ratio ?? 0);
|
|
107
|
+
const adapterOverhead = clamp01((metrics.performance?.adapter_overhead_kb ?? 0) / 100);
|
|
108
|
+
|
|
109
|
+
const H_T =
|
|
110
|
+
en.v1_budget_breach_ratio * breachRatio +
|
|
111
|
+
en.v2_residual_entropy * residualEntropy +
|
|
112
|
+
en.v3_uncovered_lattice_fraction * uncoveredLattice +
|
|
113
|
+
en.v4_visual_drift_ratio * visualDrift +
|
|
114
|
+
en.v5_adapter_overhead * adapterOverhead;
|
|
115
|
+
|
|
116
|
+
const L = S_T - H_T;
|
|
117
|
+
const regime: LagrangianRegime = L > 0.05 ? 'geodesic' : L < -0.05 ? 'pruning' : 'marginal';
|
|
118
|
+
|
|
119
|
+
return {
|
|
120
|
+
S_T: round4(S_T),
|
|
121
|
+
H_T: round4(H_T),
|
|
122
|
+
lagrangian: round4(L),
|
|
123
|
+
regime,
|
|
124
|
+
is_real_action: L > 0,
|
|
125
|
+
dominant_entropy_contributor:
|
|
126
|
+
breachRatio > 0 ? 'budget_breach' : residualEntropy > 0 ? 'residual_entropy' : 'coupling_friction',
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Suh coupling and Leinster diversity live in `designMetrics.ts` and are re-exported
|
|
131
|
+
// here so this module remains the engine the sprint names, inside its LOC budget.
|
|
132
|
+
export * from './designMetrics';
|
|
133
|
+
|
|
134
|
+
/** The estate's signal-to-noise transform of a diversity value: 1 − (1 − s)^D. */
|
|
135
|
+
export function leinsterSignalToNoise(diversity: number, similarity = 0.5): number {
|
|
136
|
+
return round4(1 - Math.pow(1 - similarity, diversity));
|
|
137
|
+
}
|