Implement chain roles and templates management in Mindnet plugin
- Added support for loading and reloading chain roles and templates from specified YAML configuration files, enhancing the plugin's flexibility. - Introduced new settings for defining paths to chain roles and templates, improving user configurability. - Implemented commands for debugging loaded chain roles and templates, providing users with insights into their configurations. - Enhanced the Mindnet settings interface to include options for managing chain roles and templates paths, improving user experience with clear descriptions and validation features.
This commit is contained in:
1 parent
15385b0129
commit
b0efa32c66
21 files changed
+3226
No files matched your search
@@ -0,0 +1,144 @@
|
||||
/**
|
||||
* Graph index for single-note scope with optional neighbor loading.
|
||||
*/
|
||||
|
||||
import type { App } from "obsidian";
|
||||
import { TFile } from "obsidian";
|
||||
import { splitIntoSections } from "../mapping/sectionParser";
|
||||
import { parseEdgesFromCallouts } from "../parser/parseEdgesFromCallouts";
|
||||
import { normalizeLinkTarget } from "../unresolvedLink/linkHelpers";
|
||||
import type { NoteSection } from "../mapping/sectionParser";
|
||||
|
||||
export interface EdgeTarget {
|
||||
file: string;
|
||||
heading: string | null;
|
||||
}
|
||||
|
||||
export interface IndexedEdge {
|
||||
rawEdgeType: string;
|
||||
source: { file: string; sectionHeading: string | null } | { file: string };
|
||||
target: EdgeTarget;
|
||||
scope: "section" | "note" | "candidate";
|
||||
evidence: {
|
||||
file: string;
|
||||
sectionHeading: string | null;
|
||||
lineRange?: { start: number; end: number };
|
||||
};
|
||||
}
|
||||
|
||||
export interface SectionNode {
|
||||
file: string;
|
||||
heading: string | null;
|
||||
}
|
||||
|
||||
const NOTE_LINKS_HEADING = "Note-Verbindungen";
|
||||
const CANDIDATES_HEADING = "Kandidaten";
|
||||
|
||||
/**
|
||||
* Parse target from link text: [[file]] or [[file#Heading]]
|
||||
*/
|
||||
function parseTarget(linkText: string): EdgeTarget {
|
||||
const normalized = normalizeLinkTarget(linkText);
|
||||
const parts = linkText.split("#");
|
||||
|
||||
if (parts.length > 1) {
|
||||
// Has heading: [[file#Heading]]
|
||||
const file = normalized;
|
||||
const headingPart = parts[1]?.split("|")[0]?.trim();
|
||||
return {
|
||||
file,
|
||||
heading: headingPart || null,
|
||||
};
|
||||
}
|
||||
|
||||
// No heading: [[file]]
|
||||
return {
|
||||
file: normalized,
|
||||
heading: null,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Build graph index for a single note.
|
||||
*/
|
||||
export async function buildNoteIndex(
|
||||
app: App,
|
||||
file: TFile
|
||||
): Promise<{ edges: IndexedEdge[]; sections: SectionNode[] }> {
|
||||
const content = await app.vault.read(file);
|
||||
const sections = splitIntoSections(content);
|
||||
const edges: IndexedEdge[] = [];
|
||||
const sectionNodes: SectionNode[] = [];
|
||||
|
||||
// Create section nodes
|
||||
for (const section of sections) {
|
||||
sectionNodes.push({
|
||||
file: file.path,
|
||||
heading: section.heading,
|
||||
});
|
||||
}
|
||||
|
||||
// Determine zone kind for each section
|
||||
for (let i = 0; i < sections.length; i++) {
|
||||
const section = sections[i];
|
||||
if (!section) continue;
|
||||
|
||||
let scope: "section" | "note" | "candidate" = "section";
|
||||
if (section.heading === NOTE_LINKS_HEADING) {
|
||||
scope = "note";
|
||||
} else if (section.heading === CANDIDATES_HEADING) {
|
||||
scope = "candidate";
|
||||
}
|
||||
|
||||
// Parse edges from section content
|
||||
const parsedEdges = parseEdgesFromCallouts(section.content);
|
||||
|
||||
for (const parsedEdge of parsedEdges) {
|
||||
// Determine source context
|
||||
const source =
|
||||
scope === "note"
|
||||
? { file: file.path }
|
||||
: { file: file.path, sectionHeading: section.heading };
|
||||
|
||||
// Process each target
|
||||
for (const targetLink of parsedEdge.targets) {
|
||||
const target = parseTarget(targetLink);
|
||||
|
||||
edges.push({
|
||||
rawEdgeType: parsedEdge.rawType,
|
||||
source,
|
||||
target,
|
||||
scope,
|
||||
evidence: {
|
||||
file: file.path,
|
||||
sectionHeading: section.heading,
|
||||
lineRange: {
|
||||
start: section.startLine + parsedEdge.lineStart,
|
||||
end: section.startLine + parsedEdge.lineEnd,
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return { edges, sections: sectionNodes };
|
||||
}
|
||||
|
||||
/**
|
||||
* Load neighbor note if needed (for incoming edge detection).
|
||||
*/
|
||||
export async function loadNeighborNote(
|
||||
app: App,
|
||||
targetFile: string
|
||||
): Promise<TFile | null> {
|
||||
try {
|
||||
const file = app.vault.getAbstractFileByPath(targetFile);
|
||||
if (file instanceof TFile) {
|
||||
return file;
|
||||
}
|
||||
} catch {
|
||||
// File not found or not accessible
|
||||
}
|
||||
return null;
|
||||
}
|
||||
Reference in new issue
Block a user