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,21 +1,141 @@
|
|
|
1
1
|
import type { APIRoute } from 'astro';
|
|
2
|
-
import { join } from 'node:path';
|
|
2
|
+
import { join, dirname } from 'node:path';
|
|
3
|
+
import { existsSync, readdirSync, statSync, readFileSync } from 'node:fs';
|
|
3
4
|
import { json, error } from '../../../lib/apiUtils';
|
|
4
|
-
import { repoRoot, workspaceRoot } from '../../../server/workspaceRoot';
|
|
5
|
+
import { repoRoot, workspaceRoot, dataRoot } from '../../../server/workspaceRoot';
|
|
5
6
|
import { PATHS, getWhitelistedDirectoryProjections } from '../../../config/pathsConfig.js';
|
|
6
7
|
import { scanRoots, toTreeFiles, type ScanRoot } from '../../../server/vfsTreeScan';
|
|
8
|
+
import { ContentHash, buildMerkleTreeFromEntries } from 'clm-kernel';
|
|
9
|
+
|
|
10
|
+
function scanSubdirEntries(dir: string, rel = ''): Array<{ path: string; data: Uint8Array }> {
|
|
11
|
+
let entries: Array<{ path: string; data: Uint8Array }> = [];
|
|
12
|
+
for (const item of readdirSync(dir, { withFileTypes: true })) {
|
|
13
|
+
const full = join(dir, item.name);
|
|
14
|
+
const sub = rel ? `${rel}/${item.name}` : item.name;
|
|
15
|
+
if (item.isDirectory()) {
|
|
16
|
+
entries.push(...scanSubdirEntries(full, sub));
|
|
17
|
+
} else {
|
|
18
|
+
entries.push({ path: sub, data: readFileSync(full) });
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return entries;
|
|
22
|
+
}
|
|
7
23
|
|
|
8
24
|
/**
|
|
9
25
|
* VFS tree federation endpoint.
|
|
10
|
-
* Supports
|
|
26
|
+
* Supports:
|
|
27
|
+
* - ?handle=<collection>: returns manifest of that collection (children with hashes and sizes) lazily (DoD-06-4).
|
|
28
|
+
* - ?scope=<id>: returns strictly bounded read-only subtrees (INV-WS-02).
|
|
11
29
|
*/
|
|
12
30
|
export const GET: APIRoute = async (context) => {
|
|
13
31
|
try {
|
|
32
|
+
const searchParams = context?.url?.searchParams ?? (context?.request ? new URL(context.request.url).searchParams : null);
|
|
33
|
+
const handleParam = searchParams?.get('handle')?.trim();
|
|
34
|
+
const scope = searchParams?.get('scope') ?? null;
|
|
35
|
+
const dRoot = dataRoot();
|
|
36
|
+
|
|
37
|
+
// Lazy Collection Manifest Endpoint (CAS-06 §2.3, DoD-06-4)
|
|
38
|
+
if (handleParam && dRoot) {
|
|
39
|
+
const cleanHandle = handleParam.replace(/^mcard:/, '').replace(/^\/+/, '').replace(/\/+$/, '');
|
|
40
|
+
const targetDir = cleanHandle ? join(dRoot, cleanHandle) : dRoot;
|
|
41
|
+
if (!existsSync(targetDir) || !statSync(targetDir).isDirectory()) {
|
|
42
|
+
return error(`Collection handle not found: ${handleParam}`, 404);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const items = readdirSync(targetDir, { withFileTypes: true });
|
|
46
|
+
const entries = items.map((item) => {
|
|
47
|
+
const itemRel = cleanHandle ? `${cleanHandle}/${item.name}` : item.name;
|
|
48
|
+
const itemFull = join(targetDir, item.name);
|
|
49
|
+
const isDir = item.isDirectory();
|
|
50
|
+
let sizeBytes = 0;
|
|
51
|
+
let qualifiedHash = '';
|
|
52
|
+
if (isDir) {
|
|
53
|
+
const sub = scanSubdirEntries(itemFull, itemRel);
|
|
54
|
+
const subTree = buildMerkleTreeFromEntries(sub);
|
|
55
|
+
qualifiedHash = subTree.hash.asPrefixed();
|
|
56
|
+
sizeBytes = subTree.sizeBytes;
|
|
57
|
+
} else {
|
|
58
|
+
const data = readFileSync(itemFull);
|
|
59
|
+
qualifiedHash = ContentHash.compute(data).asPrefixed();
|
|
60
|
+
sizeBytes = data.byteLength;
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
name: item.name,
|
|
64
|
+
path: itemRel,
|
|
65
|
+
hash: qualifiedHash,
|
|
66
|
+
isDirectory: isDir,
|
|
67
|
+
sizeBytes,
|
|
68
|
+
};
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
72
|
+
const manifestLines = entries.map((e) => `${e.name}:${e.hash}:${e.isDirectory ? 'dir' : 'file'}:${e.sizeBytes}`);
|
|
73
|
+
const manifestBytes = new TextEncoder().encode(manifestLines.join('\n') + (manifestLines.length > 0 ? '\n' : ''));
|
|
74
|
+
const manifestHash = ContentHash.compute(manifestBytes).asPrefixed();
|
|
75
|
+
|
|
76
|
+
return json(
|
|
77
|
+
{
|
|
78
|
+
success: true,
|
|
79
|
+
handle: handleParam,
|
|
80
|
+
manifestHash,
|
|
81
|
+
entries,
|
|
82
|
+
scannedAt: Date.now(),
|
|
83
|
+
},
|
|
84
|
+
200,
|
|
85
|
+
{
|
|
86
|
+
'Cache-Control': 'private, max-age=31536000, immutable',
|
|
87
|
+
'ETag': `"${manifestHash}"`,
|
|
88
|
+
}
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (dRoot) {
|
|
93
|
+
if (scope && scope.trim() !== '') {
|
|
94
|
+
const subDir = join(dRoot, scope);
|
|
95
|
+
const roots: ScanRoot[] = [{ dir: subDir, baseDir: dRoot }];
|
|
96
|
+
const rawFiles = toTreeFiles(scanRoots(roots));
|
|
97
|
+
const files = rawFiles.map((file) => ({
|
|
98
|
+
...file,
|
|
99
|
+
scope,
|
|
100
|
+
readOnly: false,
|
|
101
|
+
}));
|
|
102
|
+
return json(
|
|
103
|
+
{ success: true, scope, readOnly: false, files, scannedAt: Date.now() },
|
|
104
|
+
200,
|
|
105
|
+
{
|
|
106
|
+
'Cache-Control': 'no-cache, no-store, must-revalidate',
|
|
107
|
+
'Pragma': 'no-cache',
|
|
108
|
+
'Expires': '0',
|
|
109
|
+
}
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const roots: ScanRoot[] = [{ dir: dRoot, baseDir: dRoot }];
|
|
114
|
+
const rawFiles = toTreeFiles(scanRoots(roots));
|
|
115
|
+
const files = rawFiles.map((file) => {
|
|
116
|
+
const parts = file.path.split('/');
|
|
117
|
+
const fileScope = parts.length > 1 ? parts[0] : 'root';
|
|
118
|
+
return {
|
|
119
|
+
...file,
|
|
120
|
+
scope: fileScope,
|
|
121
|
+
readOnly: false,
|
|
122
|
+
};
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
return json(
|
|
126
|
+
{ success: true, readOnly: false, files, scannedAt: Date.now() },
|
|
127
|
+
200,
|
|
128
|
+
{
|
|
129
|
+
'Cache-Control': 'no-cache, no-store, must-revalidate',
|
|
130
|
+
'Pragma': 'no-cache',
|
|
131
|
+
'Expires': '0',
|
|
132
|
+
}
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
|
|
14
136
|
const root = repoRoot();
|
|
15
137
|
const projections = getWhitelistedDirectoryProjections();
|
|
16
138
|
const allowedScopes = projections.map((p) => p.id);
|
|
17
|
-
const searchParams = context?.url?.searchParams ?? (context?.request ? new URL(context.request.url).searchParams : null);
|
|
18
|
-
const scope = searchParams?.get('scope') ?? null;
|
|
19
139
|
|
|
20
140
|
if (scope && scope.trim() !== '') {
|
|
21
141
|
const projection = projections.find((p) => p.id === scope);
|
|
@@ -26,11 +146,10 @@ export const GET: APIRoute = async (context) => {
|
|
|
26
146
|
);
|
|
27
147
|
}
|
|
28
148
|
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const roots: ScanRoot[] = [{ dir, baseDir: root }];
|
|
149
|
+
const isWs = projection.id === PATHS.paths.workspace_dirname;
|
|
150
|
+
const dir = isWs ? workspaceRoot() : join(root, projection.path);
|
|
151
|
+
const baseDir = isWs ? dirname(workspaceRoot()) : root;
|
|
152
|
+
const roots: ScanRoot[] = [{ dir, baseDir }];
|
|
34
153
|
const rawFiles = toTreeFiles(scanRoots(roots));
|
|
35
154
|
const files = rawFiles.map((file) => ({
|
|
36
155
|
...file,
|
|
@@ -51,7 +170,7 @@ export const GET: APIRoute = async (context) => {
|
|
|
51
170
|
|
|
52
171
|
const roots: ScanRoot[] = PATHS.vfs.scan_roots.map((scanRoot) =>
|
|
53
172
|
scanRoot === PATHS.paths.workspace_dirname
|
|
54
|
-
? { dir: workspaceRoot(), baseDir:
|
|
173
|
+
? { dir: workspaceRoot(), baseDir: dirname(workspaceRoot()) }
|
|
55
174
|
: { dir: join(root, scanRoot), baseDir: root },
|
|
56
175
|
);
|
|
57
176
|
|
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
import type { APIRoute } from 'astro';
|
|
8
8
|
import { resolve, dirname } from 'node:path';
|
|
9
9
|
import { writeFileSync, mkdirSync } from 'node:fs';
|
|
10
|
-
import {
|
|
10
|
+
import { createRecord, qualify } from 'clm-kernel';
|
|
11
11
|
import { json, error } from '../../../lib/apiUtils';
|
|
12
|
-
import { repoRoot, isPathWritable } from '../../../server/workspaceRoot';
|
|
12
|
+
import { repoRoot, isPathWritable, resolveHostPath } from '../../../server/workspaceRoot';
|
|
13
13
|
|
|
14
14
|
export const POST: APIRoute = async ({ request }) => {
|
|
15
15
|
try {
|
|
@@ -31,7 +31,7 @@ export const POST: APIRoute = async ({ request }) => {
|
|
|
31
31
|
return error('Access denied: Target path is in a read-only projection', 403);
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
const absolutePath =
|
|
34
|
+
const absolutePath = resolveHostPath(targetPath, root);
|
|
35
35
|
mkdirSync(dirname(absolutePath), { recursive: true });
|
|
36
36
|
|
|
37
37
|
let bytes: Buffer;
|
|
@@ -47,7 +47,8 @@ export const POST: APIRoute = async ({ request }) => {
|
|
|
47
47
|
|
|
48
48
|
writeFileSync(absolutePath, bytes);
|
|
49
49
|
|
|
50
|
-
const
|
|
50
|
+
const record = createRecord(bytes);
|
|
51
|
+
const hash = qualify(record).asPrefixed();
|
|
51
52
|
|
|
52
53
|
return json({
|
|
53
54
|
success: true,
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
import type { Intent } from '../../core/intents/types';
|
|
12
12
|
import type { KernelEvent } from '../../core/events/kernelEvents';
|
|
13
|
-
import {
|
|
13
|
+
import { createRecord, qualify } from 'clm-kernel';
|
|
14
14
|
|
|
15
15
|
export interface DispatchResult {
|
|
16
16
|
readonly status: number;
|
|
@@ -42,12 +42,12 @@ export async function handleKernelDispatch(
|
|
|
42
42
|
switch (intent.kind) {
|
|
43
43
|
case 'TouchMCard': {
|
|
44
44
|
const content = (intent.payload && (intent.payload as any).content) || '';
|
|
45
|
-
const hash =
|
|
45
|
+
const hash = qualify(createRecord(content)).asPrefixed();
|
|
46
46
|
const event: KernelEvent = {
|
|
47
47
|
kind: 'MCardTouched',
|
|
48
48
|
intentId: intent.id,
|
|
49
49
|
uri: intent.uri,
|
|
50
|
-
hash
|
|
50
|
+
hash,
|
|
51
51
|
};
|
|
52
52
|
return {
|
|
53
53
|
status: 200,
|
|
@@ -56,7 +56,7 @@ export async function handleKernelDispatch(
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
case 'ReadMCard': {
|
|
59
|
-
const hash = intent.ref.kind === 'hash' ? intent.ref.hash :
|
|
59
|
+
const hash = intent.ref.kind === 'hash' ? intent.ref.hash : qualify(createRecord(intent.ref.handle)).asPrefixed();
|
|
60
60
|
const event: KernelEvent = {
|
|
61
61
|
kind: 'MCardRead',
|
|
62
62
|
intentId: intent.id,
|
|
@@ -73,8 +73,8 @@ export async function handleKernelDispatch(
|
|
|
73
73
|
const event: KernelEvent = {
|
|
74
74
|
kind: 'ExecutionReceipt',
|
|
75
75
|
intentId: intent.id,
|
|
76
|
-
receiptHash:
|
|
77
|
-
outputHash:
|
|
76
|
+
receiptHash: qualify(createRecord(intent.pcardRef)).asPrefixed(),
|
|
77
|
+
outputHash: qualify(createRecord(intent.inputRef || '')).asPrefixed(),
|
|
78
78
|
fiberId: `fiber:${intent.id}`,
|
|
79
79
|
};
|
|
80
80
|
return {
|
|
@@ -88,7 +88,7 @@ export async function handleKernelDispatch(
|
|
|
88
88
|
kind: 'ContinuationResumed',
|
|
89
89
|
intentId: intent.id,
|
|
90
90
|
token: intent.token,
|
|
91
|
-
receiptHash:
|
|
91
|
+
receiptHash: qualify(createRecord(intent.token)).asPrefixed(),
|
|
92
92
|
};
|
|
93
93
|
return {
|
|
94
94
|
status: 200,
|
|
@@ -100,7 +100,7 @@ export async function handleKernelDispatch(
|
|
|
100
100
|
const event: KernelEvent = {
|
|
101
101
|
kind: 'ActionApplied',
|
|
102
102
|
intentId: intent.id,
|
|
103
|
-
postHash:
|
|
103
|
+
postHash: qualify(createRecord(intent.action.type)).asPrefixed(),
|
|
104
104
|
};
|
|
105
105
|
return {
|
|
106
106
|
status: 200,
|
|
@@ -39,6 +39,10 @@ import { registerCacheInvalidator } from './serverMemoryCacheSignal.mjs';
|
|
|
39
39
|
const fileSystemRepository = new FileSystemArtifactRepository(DEFAULT_ARTIFACTS_PUBLIC_DIR);
|
|
40
40
|
const collectionRepository = new ServerMemoryArtifactRepository();
|
|
41
41
|
|
|
42
|
+
export function getCollectionRepository(): ServerMemoryArtifactRepository {
|
|
43
|
+
return collectionRepository;
|
|
44
|
+
}
|
|
45
|
+
|
|
42
46
|
// Register so the .mjs WS layer can invalidate our in-memory cache
|
|
43
47
|
registerCacheInvalidator(() => {
|
|
44
48
|
collectionRepository.invalidateCache();
|
|
@@ -320,13 +324,6 @@ export async function deleteArtifact(handle: string): Promise<void> {
|
|
|
320
324
|
}
|
|
321
325
|
}
|
|
322
326
|
|
|
323
|
-
/**
|
|
324
|
-
* Delete a single version history entry for an artifact.
|
|
325
|
-
*/
|
|
326
|
-
export async function deleteHistoryEntry(handle: string, previousHash: string): Promise<void> {
|
|
327
|
-
// Always operate on servermemory.db — the single source of truth for history.
|
|
328
|
-
await (collectionRepository as any).deleteHistoryEntry(handle, previousHash);
|
|
329
|
-
}
|
|
330
327
|
|
|
331
328
|
/**
|
|
332
329
|
* Revert the latest version of an artifact: roll handle_registry.current_hash back
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fs from 'fs/promises';
|
|
2
2
|
import path from 'path';
|
|
3
|
-
import
|
|
3
|
+
import { createRecord, qualify } from 'clm-kernel';
|
|
4
4
|
import { buildServerFsHandle, artifactFetchPathFromPath, artifactPathFromHandle, LEGACY_LOCAL_PREFIX_SLASH } from '../utils/artifactHandles';
|
|
5
5
|
import { inferArtifactType } from '../domain/artifactClassification';
|
|
6
6
|
import type { ArtifactMeta } from '../domain/artifacts';
|
|
@@ -141,8 +141,9 @@ export class FileSystemArtifactRepository implements ArtifactRepository {
|
|
|
141
141
|
throw new Error(`Failed to save or find artifact metadata for ${handle}`);
|
|
142
142
|
}
|
|
143
143
|
|
|
144
|
-
// Compute content hash
|
|
145
|
-
const
|
|
144
|
+
// Compute content hash via kernel record
|
|
145
|
+
const record = createRecord(content);
|
|
146
|
+
const hash = qualify(record).asPrefixed();
|
|
146
147
|
meta.hash = hash;
|
|
147
148
|
|
|
148
149
|
return meta;
|
package/src/server/clmRunner.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import vm from 'node:vm';
|
|
|
7
7
|
import YAML from 'yaml';
|
|
8
8
|
import { CLM_RUNNER_TIMEOUT_MS, resolveServerConfig } from './serverConfig.js';
|
|
9
9
|
import { LEGACY_LOCAL_PREFIX_SLASH, SERVER_FS_PREFIX_SLASH, SERVER_COL_PREFIX_SLASH } from '../shared/handleConstants.js';
|
|
10
|
-
import { MCard } from '
|
|
10
|
+
import { MCard } from 'clm-kernel';
|
|
11
11
|
|
|
12
12
|
const execFileAsync = promisify(execFile);
|
|
13
13
|
const { artifactsDir: ARTIFACTS_DIR } = resolveServerConfig(process.env);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MCardCollection, NodeSqliteBackend } from 'clm-kernel';
|
|
2
2
|
|
|
3
3
|
export function createCollectionOwner(dbPath) {
|
|
4
4
|
let collection = null;
|
|
@@ -11,10 +11,10 @@ export function createCollectionOwner(dbPath) {
|
|
|
11
11
|
|
|
12
12
|
console.log(`[WS] Initializing Storage at ${dbPath}`);
|
|
13
13
|
try {
|
|
14
|
-
engine =
|
|
15
|
-
console.log(`[WS]
|
|
14
|
+
engine = new NodeSqliteBackend(dbPath);
|
|
15
|
+
console.log(`[WS] NodeSqliteBackend created OK for ${dbPath}`);
|
|
16
16
|
} catch (err) {
|
|
17
|
-
console.error(`[WS]
|
|
17
|
+
console.error(`[WS] NodeSqliteBackend FAILED for ${dbPath}:`, err);
|
|
18
18
|
console.warn('[WS] Falling back to mock storage (no persistence)');
|
|
19
19
|
useMock = true;
|
|
20
20
|
return null;
|
|
@@ -46,7 +46,7 @@ export function createCollectionOwner(dbPath) {
|
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
collection = new
|
|
49
|
+
collection = new MCardCollection(e);
|
|
50
50
|
return collection;
|
|
51
51
|
}
|
|
52
52
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createRecord } from 'clm-kernel';
|
|
2
2
|
import { WS_MESSAGE_TYPES } from '../../shared/wsProtocol.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -39,10 +39,10 @@ export async function persistSealedResult({ collectionOwner, sealExecutionResult
|
|
|
39
39
|
};
|
|
40
40
|
|
|
41
41
|
const sealed = sealExecutionResult(vCardContent);
|
|
42
|
-
const
|
|
43
|
-
await collection.add(
|
|
42
|
+
const record = createRecord(JSON.stringify(sealed.original, null, 2));
|
|
43
|
+
await collection.add(record);
|
|
44
44
|
|
|
45
|
-
return { hash:
|
|
45
|
+
return { hash: record.hash, vCardContent };
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
/**
|
|
@@ -71,11 +71,11 @@ export async function persistLLMInteractionEvents({ collectionOwner, notificatio
|
|
|
71
71
|
vcard_policy_hash: request.handle || 'unknown-context'
|
|
72
72
|
};
|
|
73
73
|
|
|
74
|
-
const
|
|
75
|
-
const existingUserCard = await collection.get(
|
|
74
|
+
const userRecord = createRecord(JSON.stringify(userPromptContent, null, 2));
|
|
75
|
+
const existingUserCard = await collection.get(userRecord.hash);
|
|
76
76
|
|
|
77
77
|
if (!existingUserCard) {
|
|
78
|
-
await collection.add(
|
|
78
|
+
await collection.add(userRecord);
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
if (notificationService && request.clientId) {
|
|
@@ -93,15 +93,15 @@ export async function persistLLMInteractionEvents({ collectionOwner, notificatio
|
|
|
93
93
|
timestamp: new Date().toISOString(),
|
|
94
94
|
contentType: 'text/markdown',
|
|
95
95
|
content: runResult.result,
|
|
96
|
-
pre_condition_hash:
|
|
96
|
+
pre_condition_hash: userRecord.hash,
|
|
97
97
|
trace_execution_hash: parentExecutionHash
|
|
98
98
|
};
|
|
99
99
|
|
|
100
|
-
const
|
|
101
|
-
const existingLlmCard = await collection.get(
|
|
100
|
+
const llmRecord = createRecord(JSON.stringify(llmResponseContent, null, 2));
|
|
101
|
+
const existingLlmCard = await collection.get(llmRecord.hash);
|
|
102
102
|
|
|
103
103
|
if (!existingLlmCard) {
|
|
104
|
-
await collection.add(
|
|
104
|
+
await collection.add(llmRecord);
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
if (notificationService && request.clientId) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { computeHash } from 'clm-kernel';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Result Sealing Service — VCard provenance layer.
|
|
@@ -94,5 +94,5 @@ export function verifySeal(sealedContent) {
|
|
|
94
94
|
|
|
95
95
|
/** @param {string} data */
|
|
96
96
|
function sha256(data) {
|
|
97
|
-
return
|
|
97
|
+
return computeHash('sha256', data);
|
|
98
98
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import { access, readFile, readdir, stat } from 'fs/promises';
|
|
3
3
|
import { ClmChapterLoader } from 'clm-kernel/layer0';
|
|
4
|
-
import {
|
|
4
|
+
import { createRecord, qualify } from 'clm-kernel';
|
|
5
5
|
import { buildServerFsHandle } from '../shared/handleConstants.js';
|
|
6
6
|
import { PATHS } from '../config/pathsConfig.js';
|
|
7
|
+
import { isStoreFile } from '../edge/storeFilter.js';
|
|
7
8
|
|
|
8
9
|
/** Ignore semantics resolve from the single `ingest.ignore` source (INV-PC-03). */
|
|
9
10
|
const IGNORED_EXT_SET = new Set(PATHS.ingest.ignore.extensions);
|
|
@@ -12,7 +13,6 @@ const IGNORED_FILENAMES = new Set(PATHS.ingest.ignore.filenames);
|
|
|
12
13
|
const SKIP_DOTFILES = PATHS.ingest.ignore.skip_dotfiles;
|
|
13
14
|
const SERVER_FS_PREFIX = PATHS.handles.server_fs;
|
|
14
15
|
|
|
15
|
-
|
|
16
16
|
/**
|
|
17
17
|
* File Ingest Service — Filesystem → Collection Importer.
|
|
18
18
|
*
|
|
@@ -34,6 +34,9 @@ const SERVER_FS_PREFIX = PATHS.handles.server_fs;
|
|
|
34
34
|
* @returns {Promise<{ action: 'created' | 'updated' | 'unchanged' | 'deleted'; handle: string; hash?: string } | null>}
|
|
35
35
|
*/
|
|
36
36
|
export async function ingestFileChange(artifactsDir, filename, collectionOwner) {
|
|
37
|
+
if (isStoreFile(filename)) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
37
40
|
const fullPath = path.join(artifactsDir, filename);
|
|
38
41
|
const handle = buildServerFsHandle(filename);
|
|
39
42
|
|
|
@@ -59,21 +62,27 @@ export async function ingestFileChange(artifactsDir, filename, collectionOwner)
|
|
|
59
62
|
}
|
|
60
63
|
}
|
|
61
64
|
|
|
62
|
-
const
|
|
65
|
+
const record = createRecord(buf);
|
|
66
|
+
const qualifiedHash = qualify(record);
|
|
63
67
|
const collection = await collectionOwner.getCollection();
|
|
64
68
|
const existingHash = await collection.resolveHandle(handle);
|
|
65
69
|
|
|
66
|
-
|
|
67
|
-
|
|
70
|
+
const bareHex = record.hash.includes(':') ? record.hash.split(':')[1] : record.hash;
|
|
71
|
+
const existingHex = (existingHash && typeof existingHash === 'object' && 'asHex' in existingHash)
|
|
72
|
+
? existingHash.asHex()
|
|
73
|
+
: (String(existingHash || '').includes(':') ? String(existingHash).split(':')[1] : String(existingHash || ''));
|
|
74
|
+
|
|
75
|
+
if (existingHex === bareHex) {
|
|
76
|
+
return { action: 'unchanged', handle, hash: qualifiedHash };
|
|
68
77
|
}
|
|
69
78
|
|
|
70
79
|
if (existingHash) {
|
|
71
|
-
await collection.updateHandle(handle,
|
|
72
|
-
return { action: 'updated', handle, hash:
|
|
80
|
+
await collection.updateHandle(handle, record);
|
|
81
|
+
return { action: 'updated', handle, hash: qualifiedHash };
|
|
73
82
|
}
|
|
74
83
|
|
|
75
|
-
await collection.addWithHandle(
|
|
76
|
-
return { action: 'created', handle, hash:
|
|
84
|
+
await collection.addWithHandle(record, handle);
|
|
85
|
+
return { action: 'created', handle, hash: qualifiedHash };
|
|
77
86
|
}
|
|
78
87
|
|
|
79
88
|
/**
|
|
@@ -126,6 +135,9 @@ export async function ingestDirectory(artifactsDir, collectionOwner, options = {
|
|
|
126
135
|
}
|
|
127
136
|
|
|
128
137
|
// Skip non-artifact files
|
|
138
|
+
if (isStoreFile(entry.name)) {
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
129
141
|
const ext = path.extname(entry.name).toLowerCase();
|
|
130
142
|
if (IGNORED_EXT_SET.has(ext)) continue;
|
|
131
143
|
if ((SKIP_DOTFILES && entry.name.startsWith('.')) || IGNORED_FILENAMES.has(entry.name)) continue;
|
|
@@ -2,6 +2,7 @@ import { watch } from 'fs';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { EventEmitter } from 'events';
|
|
4
4
|
import { PATHS } from '../config/pathsConfig.js';
|
|
5
|
+
import { isStoreFile } from '../edge/storeFilter.js';
|
|
5
6
|
|
|
6
7
|
const DEBOUNCE_MS = PATHS.ingest.watch_debounce_ms;
|
|
7
8
|
const IGNORED_PATTERNS = PATHS.ingest.ignore.patterns;
|
|
@@ -19,7 +20,9 @@ export function createFileWatcherService(artifactsDir) {
|
|
|
19
20
|
const debounceTimers = new Map();
|
|
20
21
|
|
|
21
22
|
function shouldIgnore(filename) {
|
|
22
|
-
|
|
23
|
+
if (IGNORED_PATTERNS.some(pattern => filename.includes(pattern))) return true;
|
|
24
|
+
if (isStoreFile(filename)) return true;
|
|
25
|
+
return false;
|
|
23
26
|
}
|
|
24
27
|
|
|
25
28
|
function start() {
|
|
@@ -1,14 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* File watcher event handler.
|
|
3
|
-
*
|
|
4
|
-
* Encapsulates the side-effects triggered when the file system watcher detects
|
|
5
|
-
* changes in the artifacts directory:
|
|
6
|
-
* 1. Broadcasts ARTIFACTS_CHANGED to all connected WS clients
|
|
7
|
-
* 2. Auto-ingests changes into servermemory.db for version tracking
|
|
8
|
-
*/
|
|
9
1
|
import { WS_MESSAGE_TYPES } from '../../shared/wsProtocol.js';
|
|
10
2
|
import { ingestFileChange } from '../fileIngestService.mjs';
|
|
11
3
|
import { signalCacheInvalidate } from '../serverMemoryCacheSignal.mjs';
|
|
4
|
+
import { formatNotification, GATEWAY_METHODS } from 'clm-kernel';
|
|
12
5
|
|
|
13
6
|
/**
|
|
14
7
|
* Create a handler for file watcher 'change' events.
|
|
@@ -22,10 +15,25 @@ export function createFileChangeHandler({ artifactsDir, notificationService, ser
|
|
|
22
15
|
return async ({ eventType, filename }) => {
|
|
23
16
|
try {
|
|
24
17
|
const result = await ingestFileChange(artifactsDir, filename, serverMemoryOwner);
|
|
25
|
-
if (!result) {
|
|
18
|
+
if (!result || result.action === 'unchanged') {
|
|
26
19
|
return;
|
|
27
20
|
}
|
|
28
21
|
|
|
22
|
+
// Sprint CAS-05 / R9: Emit clm.name.transition notification with kernel's formatNotification
|
|
23
|
+
const transitionKind = result.action === 'deleted' ? 'DELETE' : (result.action === 'created' ? 'CREATE' : 'UPDATE');
|
|
24
|
+
const qualifiedHashStr = result.hash ? String(result.hash) : '';
|
|
25
|
+
const transitionPayload = {
|
|
26
|
+
hash: qualifiedHashStr,
|
|
27
|
+
handle: result.handle,
|
|
28
|
+
kind: transitionKind,
|
|
29
|
+
from: null,
|
|
30
|
+
to: result.action === 'deleted' ? null : qualifiedHashStr,
|
|
31
|
+
author: 'did:clm:agent:watcher',
|
|
32
|
+
clock: { watcher: Date.now() },
|
|
33
|
+
};
|
|
34
|
+
const notificationJson = formatNotification(GATEWAY_METHODS.NAME_TRANSITION, transitionPayload);
|
|
35
|
+
notificationService.broadcastRaw?.(notificationJson);
|
|
36
|
+
|
|
29
37
|
await notificationService.broadcastToAll({
|
|
30
38
|
type: WS_MESSAGE_TYPES.ARTIFACTS_CHANGED,
|
|
31
39
|
title: 'Server files changed',
|
|
@@ -36,7 +44,7 @@ export function createFileChangeHandler({ artifactsDir, notificationService, ser
|
|
|
36
44
|
hash: result.hash,
|
|
37
45
|
filename
|
|
38
46
|
});
|
|
39
|
-
console.log(`[WS] Broadcasted ARTIFACTS_CHANGED to all clients for ${result.handle} (${result.action})`);
|
|
47
|
+
console.log(`[WS] Broadcasted clm.name.transition & ARTIFACTS_CHANGED to all clients for ${result.handle} (${result.action})`);
|
|
40
48
|
|
|
41
49
|
if (result.action !== 'unchanged' && result.action !== 'deleted') {
|
|
42
50
|
console.log(`[WS] Ingested ${result.action} for ${filename} (handle: ${result.handle}, hash: ${result.hash})`);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { WS_MESSAGE_TYPES } from '../../shared/wsProtocol.js';
|
|
2
|
-
import {
|
|
2
|
+
import { createRecord } from 'clm-kernel';
|
|
3
3
|
import { isExecutionLogPayload } from '../../domain/executionSchema.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -24,9 +24,9 @@ export function createSaveExecutionLogHandler({ logsCollectionOwner, clients })
|
|
|
24
24
|
...payload
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
const
|
|
28
|
-
await logsColl.add(
|
|
29
|
-
console.log(`[WS] Execution log saved as MCard: ${
|
|
27
|
+
const record = createRecord(JSON.stringify(logData, null, 2));
|
|
28
|
+
await logsColl.add(record);
|
|
29
|
+
console.log(`[WS] Execution log saved as MCard: ${record.hash}`);
|
|
30
30
|
|
|
31
31
|
// --- Broadcast governance telemetry to all connected clients ---
|
|
32
32
|
if (payload.governance_telemetry && clients) {
|
|
@@ -34,7 +34,7 @@ export function createSaveExecutionLogHandler({ logsCollectionOwner, clients })
|
|
|
34
34
|
const telemetryUpdate = JSON.stringify({
|
|
35
35
|
type: WS_MESSAGE_TYPES.TELEMETRY_UPDATE,
|
|
36
36
|
data: {
|
|
37
|
-
id:
|
|
37
|
+
id: record.hash,
|
|
38
38
|
timestamp: Date.now(),
|
|
39
39
|
possibilityMagnitude: gt.M ?? 0,
|
|
40
40
|
governanceNarrowing: gt.N ?? 0,
|
|
@@ -57,7 +57,7 @@ export function createSaveExecutionLogHandler({ logsCollectionOwner, clients })
|
|
|
57
57
|
return {
|
|
58
58
|
type: WS_MESSAGE_TYPES.EXECUTION_LOG_SAVED,
|
|
59
59
|
success: true,
|
|
60
|
-
hash:
|
|
60
|
+
hash: record.hash
|
|
61
61
|
};
|
|
62
62
|
};
|
|
63
63
|
}
|
|
@@ -137,6 +137,18 @@ export function createNotificationService({ clients, pushSubscriptions, pendingN
|
|
|
137
137
|
return results;
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
+
function broadcastRaw(rawMessage) {
|
|
141
|
+
for (const [clientId, client] of clients) {
|
|
142
|
+
if (client && client.ws && client.ws.readyState === 1 /* OPEN */) {
|
|
143
|
+
try {
|
|
144
|
+
client.ws.send(rawMessage);
|
|
145
|
+
} catch (e) {
|
|
146
|
+
console.error('[Notify] broadcastRaw error:', e);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
140
152
|
return {
|
|
141
153
|
NotificationPriority,
|
|
142
154
|
sendNotification,
|
|
@@ -144,6 +156,7 @@ export function createNotificationService({ clients, pushSubscriptions, pendingN
|
|
|
144
156
|
storePendingNotification,
|
|
145
157
|
deliverPendingNotifications,
|
|
146
158
|
broadcastToAll,
|
|
147
|
-
broadcastToChannel
|
|
159
|
+
broadcastToChannel,
|
|
160
|
+
broadcastRaw,
|
|
148
161
|
};
|
|
149
162
|
}
|
|
@@ -2,7 +2,7 @@ import fs from 'fs/promises';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { createCollectionOwner } from '../collectionOwner.mjs';
|
|
4
4
|
import { resolveServerConfig } from '../serverConfig.js';
|
|
5
|
-
import {
|
|
5
|
+
import { createRecord } from 'clm-kernel';
|
|
6
6
|
|
|
7
7
|
const config = resolveServerConfig(process.env);
|
|
8
8
|
const SEEDING_DB_PATH = config.seedingMemoryDbPath;
|
|
@@ -34,13 +34,13 @@ async function buildSeedingMemory() {
|
|
|
34
34
|
const contentStr = await fs.readFile(filePath, 'utf-8');
|
|
35
35
|
const contentBytes = new TextEncoder().encode(contentStr);
|
|
36
36
|
|
|
37
|
-
const
|
|
37
|
+
const record = createRecord(contentBytes);
|
|
38
38
|
// The handle format in MCard Studio is typically local/dir/file
|
|
39
39
|
// Wait, what should be the handle? In loadArtifactIndex it's 'local/clm/chapter_01_arithmetic/addition_js.yaml'
|
|
40
40
|
// For browsermemory, the handle is just `local/clm/chapter_01_arithmetic/addition_js.yaml` (when fetched lazily)
|
|
41
41
|
const handle = `local/${relativeDir}/${file}`;
|
|
42
42
|
|
|
43
|
-
await collection.addWithHandle(
|
|
43
|
+
await collection.addWithHandle(record, handle);
|
|
44
44
|
addedCount++;
|
|
45
45
|
console.log(`[buildSeedingMemory] Added ${handle}`);
|
|
46
46
|
}
|