@@ -10,12 +10,11 @@ import type { OpenClawConfig } from "../api.js";
1010import type { ResolvedMemoryWikiConfig } from "./config.js" ;
1111import { appendMemoryWikiLog } from "./log.js" ;
1212import { renderMarkdownFence , renderWikiMarkdown , slugifyWikiSegment } from "./markdown.js" ;
13+ import { writeImportedSourcePage } from "./source-page-shared.js" ;
1314import { pathExists , resolveArtifactKey } from "./source-path-shared.js" ;
1415import {
1516 pruneImportedSourceEntries ,
1617 readMemoryWikiSourceSyncState ,
17- setImportedSourceEntry ,
18- shouldSkipImportedSourceWrite ,
1918 writeMemoryWikiSourceSyncState ,
2019} from "./source-sync-state.js" ;
2120import { initializeMemoryWikiVault } from "./vault.js" ;
@@ -184,9 +183,6 @@ async function writeBridgeSourcePage(params: {
184183 relativePath : params . artifact . relativePath ,
185184 } ) ;
186185 const title = resolveBridgeTitle ( params . artifact , params . agentIds ) ;
187- const pageAbsPath = path . join ( params . config . vault . path , pagePath ) ;
188- const created = ! ( await pathExists ( pageAbsPath ) ) ;
189- const sourceUpdatedAt = new Date ( params . sourceUpdatedAtMs ) . toISOString ( ) ;
190186 const renderFingerprint = createHash ( "sha1" )
191187 . update (
192188 JSON . stringify ( {
@@ -197,71 +193,56 @@ async function writeBridgeSourcePage(params: {
197193 } ) ,
198194 )
199195 . digest ( "hex" ) ;
200- const shouldSkip = await shouldSkipImportedSourceWrite ( {
196+ return writeImportedSourcePage ( {
201197 vaultRoot : params . config . vault . path ,
202198 syncKey : params . artifact . syncKey ,
203- expectedPagePath : pagePath ,
204- expectedSourcePath : params . artifact . absolutePath ,
199+ sourcePath : params . artifact . absolutePath ,
205200 sourceUpdatedAtMs : params . sourceUpdatedAtMs ,
206201 sourceSize : params . sourceSize ,
207202 renderFingerprint,
203+ pagePath,
204+ group : "bridge" ,
208205 state : params . state ,
209- } ) ;
210- if ( shouldSkip ) {
211- return { pagePath, changed : false , created } ;
212- }
213- const raw = await fs . readFile ( params . artifact . absolutePath , "utf8" ) ;
214- const contentLanguage = params . artifact . artifactType === "memory-events" ? "json" : "markdown" ;
215- const rendered = renderWikiMarkdown ( {
216- frontmatter : {
217- pageType : "source" ,
218- id : pageId ,
219- title,
220- sourceType :
221- params . artifact . artifactType === "memory-events" ? "memory-bridge-events" : "memory-bridge" ,
222- sourcePath : params . artifact . absolutePath ,
223- bridgeRelativePath : params . artifact . relativePath ,
224- bridgeWorkspaceDir : params . artifact . workspaceDir ,
225- bridgeAgentIds : params . agentIds ,
226- status : "active" ,
227- updatedAt : sourceUpdatedAt ,
228- } ,
229- body : [
230- `# ${ title } ` ,
231- "" ,
232- "## Bridge Source" ,
233- `- Workspace: \`${ params . artifact . workspaceDir } \`` ,
234- `- Relative path: \`${ params . artifact . relativePath } \`` ,
235- `- Kind: \`${ params . artifact . artifactType } \`` ,
236- `- Agents: ${ params . agentIds . length > 0 ? params . agentIds . join ( ", " ) : "unknown" } ` ,
237- `- Updated: ${ sourceUpdatedAt } ` ,
238- "" ,
239- "## Content" ,
240- renderMarkdownFence ( raw , contentLanguage ) ,
241- "" ,
242- "## Notes" ,
243- "<!-- openclaw:human:start -->" ,
244- "<!-- openclaw:human:end -->" ,
245- "" ,
246- ] . join ( "\n" ) ,
247- } ) ;
248- const existing = await fs . readFile ( pageAbsPath , "utf8" ) . catch ( ( ) => "" ) ;
249- if ( existing !== rendered ) {
250- await fs . writeFile ( pageAbsPath , rendered , "utf8" ) ;
251- }
252- setImportedSourceEntry ( {
253- syncKey : params . artifact . syncKey ,
254- state : params . state ,
255- entry : {
256- group : "bridge" ,
257- pagePath,
258- sourcePath : params . artifact . absolutePath ,
259- sourceUpdatedAtMs : params . sourceUpdatedAtMs ,
260- sourceSize : params . sourceSize ,
261- renderFingerprint,
206+ buildRendered : ( raw , updatedAt ) => {
207+ const contentLanguage =
208+ params . artifact . artifactType === "memory-events" ? "json" : "markdown" ;
209+ return renderWikiMarkdown ( {
210+ frontmatter : {
211+ pageType : "source" ,
212+ id : pageId ,
213+ title,
214+ sourceType :
215+ params . artifact . artifactType === "memory-events"
216+ ? "memory-bridge-events"
217+ : "memory-bridge" ,
218+ sourcePath : params . artifact . absolutePath ,
219+ bridgeRelativePath : params . artifact . relativePath ,
220+ bridgeWorkspaceDir : params . artifact . workspaceDir ,
221+ bridgeAgentIds : params . agentIds ,
222+ status : "active" ,
223+ updatedAt,
224+ } ,
225+ body : [
226+ `# ${ title } ` ,
227+ "" ,
228+ "## Bridge Source" ,
229+ `- Workspace: \`${ params . artifact . workspaceDir } \`` ,
230+ `- Relative path: \`${ params . artifact . relativePath } \`` ,
231+ `- Kind: \`${ params . artifact . artifactType } \`` ,
232+ `- Agents: ${ params . agentIds . length > 0 ? params . agentIds . join ( ", " ) : "unknown" } ` ,
233+ `- Updated: ${ updatedAt } ` ,
234+ "" ,
235+ "## Content" ,
236+ renderMarkdownFence ( raw , contentLanguage ) ,
237+ "" ,
238+ "## Notes" ,
239+ "<!-- openclaw:human:start -->" ,
240+ "<!-- openclaw:human:end -->" ,
241+ "" ,
242+ ] . join ( "\n" ) ,
243+ } ) ;
262244 } ,
263245 } ) ;
264- return { pagePath, changed : existing !== rendered , created } ;
265246}
266247
267248export async function syncMemoryWikiBridgeSources ( params : {
0 commit comments