Enhance chain inspection functionality with editor content support
Node.js build / build (20.x) (push) Waiting to run
Node.js build / build (22.x) (push) Waiting to run

- Updated `inspectChains` to accept optional `editorContent`, allowing for real-time inspection without relying on potentially stale vault data.
- Introduced `buildNoteIndexFromContent` to facilitate graph indexing directly from provided content.
- Improved handling of template matching profiles in `ChainWorkbenchModal`, ensuring accurate context during chain inspections.
- Added debug logging for better traceability of the chain inspection process.
This commit is contained in:
Lars committed 2026-02-06 12:02:51 +01:00
1 parent dbd76b764d
commit 99c77ef616
5 files changed
+200 -20

No files matched your search

+11 -6
View File
@@ -679,6 +679,8 @@ function computeFindings(
/**
* Inspect chains for current section context.
* @param editorContent Optional: If provided, use this content instead of reading from vault.
* This is useful when the file was just modified and vault cache is stale.
*/
export async function inspectChains(
app: App,
@@ -688,7 +690,8 @@ export async function inspectChains(
edgeVocabularyPath?: string,
chainTemplates?: ChainTemplatesConfig | null,
templatesLoadResult?: { path: string; status: string; loadedAt: number | null; templateCount: number },
templateMatchingProfileName?: string
templateMatchingProfileName?: string,
editorContent?: string
): Promise<ChainInspectorReport> {
// Build index for current note
const currentFile = app.vault.getAbstractFileByPath(context.file);
@@ -700,10 +703,11 @@ export async function inspectChains(
throw new Error(`File not found or not a markdown file: ${context.file}`);
}
const { edges: currentEdges, sections } = await buildNoteIndex(
app,
currentFile as TFile
);
// Use editor content if provided, otherwise read from vault
const { buildNoteIndex, buildNoteIndexFromContent } = await import("./graphIndex");
const { edges: currentEdges, sections } = editorContent
? await buildNoteIndexFromContent(app, currentFile as TFile, editorContent)
: await buildNoteIndex(app, currentFile as TFile);
// Collect all outgoing targets to load neighbor notes
// Respect includeNoteLinks and includeCandidates toggles
@@ -905,7 +909,8 @@ export async function inspectChains(
}
// Get section content for gap analysis
const content = await app.vault.read(currentFile as TFile);
// Use editor content if provided, otherwise read from vault
const content = editorContent || await app.vault.read(currentFile as TFile);
const sectionsWithContent = splitIntoSections(content);
const currentSectionContent =
sectionsWithContent[context.sectionIndex]?.content || "";
+15 -1
View File
@@ -83,13 +83,27 @@ function parseTarget(linkText: string, currentFilePath: string, sections: NoteSe
}
/**
* Build graph index for a single note.
* Build graph index for a single note from file content.
* Use buildNoteIndexFromContent if you have the content already (e.g., from editor).
*/
export async function buildNoteIndex(
app: App,
file: TFile
): Promise<{ edges: IndexedEdge[]; sections: SectionNode[] }> {
const content = await app.vault.read(file);
return buildNoteIndexFromContent(app, file, content);
}
/**
* Build graph index for a single note from provided content.
* This is useful when you have the content from an editor and want to avoid
* reading stale data from the vault cache.
*/
export async function buildNoteIndexFromContent(
app: App,
file: TFile,
content: string
): Promise<{ edges: IndexedEdge[]; sections: SectionNode[] }> {
const sections = splitIntoSections(content);
const edges: IndexedEdge[] = [];
const sectionNodes: SectionNode[] = [];