Refactor plugin to Mindnet Causal Assistant with enhanced vocabulary management and linting features. Updated manifest and package files to reflect new plugin details and dependencies. Added commands for reloading vocabulary and validating notes.
Node.js build / build (20.x) (push) Waiting to run
Node.js build / build (22.x) (push) Waiting to run

This commit is contained in:
Lars committed 2026-01-15 11:34:29 +01:00
1 parent dc2fa22c4d
commit 9b8550c387
31 files changed
+3133 -320

No files matched your search

+64
View File
@@ -0,0 +1,64 @@
import type { EdgeVocabulary, NormalizeResult } from "./types";
/**
* Wrapper class for edge vocabulary that provides convenient lookup methods.
*/
export class Vocabulary {
private vocab: EdgeVocabulary;
constructor(vocab: EdgeVocabulary) {
this.vocab = vocab;
}
/**
* Get canonical edge type from raw input (case-insensitive).
* Returns null if not found.
*/
getCanonical(raw: string): string | null {
const lowerRaw = raw.toLowerCase();
// Check if it's already a canonical
for (const [canonical] of this.vocab.byCanonical) {
if (canonical.toLowerCase() === lowerRaw) {
return canonical;
}
}
// Check aliases
const canonical = this.vocab.aliasToCanonical.get(lowerRaw);
return canonical ?? null;
}
/**
* Get inverse edge type for a canonical type.
* Returns null if not found or no inverse defined.
*/
getInverse(canonical: string): string | null {
const entry = this.vocab.byCanonical.get(canonical);
return entry?.inverse ?? null;
}
/**
* Normalize a raw edge type string to canonical and inverse.
*/
normalize(raw: string): NormalizeResult {
const canonical = this.getCanonical(raw);
const inverse = canonical ? this.getInverse(canonical) : null;
return {
raw,
canonical,
inverse,
};
}
/**
* Get statistics about the vocabulary.
*/
getStats(): { canonicalCount: number; aliasCount: number } {
return {
canonicalCount: this.vocab.byCanonical.size,
aliasCount: this.vocab.aliasToCanonical.size,
};
}
}
+27
View File
@@ -0,0 +1,27 @@
import type { App, TFile } from "obsidian";
import { normalizeVaultPath } from "../settings";
export class VocabularyLoader {
/**
* Loads a text file from the currently opened Obsidian vault.
* @param app Obsidian App
* @param vaultRelativePath e.g. "_system/dictionary/edge_vocabulary.md"
*/
static async loadText(app: App, vaultRelativePath: string): Promise<string> {
const p = normalizeVaultPath(vaultRelativePath);
const abstract = app.vault.getAbstractFileByPath(p);
if (!abstract) {
throw new Error(`Vocabulary file not found in vault: "${p}"`);
}
// Guard: Only files can be read
const file = abstract as TFile;
// TFile has 'extension' and 'path' properties; if it isn't a file this will usually fail at runtime.
if (!(file && typeof file.path === "string")) {
throw new Error(`Path is not a file: "${p}"`);
}
return await app.vault.read(file);
}
}
View File
Whitespace-only changes.
+105
View File
@@ -0,0 +1,105 @@
import type { EdgeVocabulary } from "./types";
const BACKTICK_RE = /`([^`]+)`/g;
/**
* Parses markdown tables containing edge vocabulary definitions.
*
* Expected format:
* | System-Typ (Canonical) | Inverser Typ | Erlaubte Aliasse (User) | Beschreibung ... |
* | **`caused_by`** | `resulted_in` | `ausgelöst_durch`, `wegen`, ... | ... |
*
* Rules:
* - Extract all backticked tokens from each row
* - First token = canonical (may be wrapped in ** **)
* - Second token = inverse (optional)
* - Remaining tokens = aliases (skip if cell contains "(Kein Alias)")
* - Skip rows with less than 1 token (with warning counter)
* - Store canonical as-is, but use lowercase for lookup keys
*/
export function parseEdgeVocabulary(md: string): EdgeVocabulary {
const lines = md.split(/\r?\n/);
const byCanonical = new Map<string, { canonical: string; inverse?: string; aliases: string[] }>();
const aliasToCanonical = new Map<string, string>();
let skippedRows = 0;
for (const line of lines) {
// Skip header separator rows (e.g., "| :--- | :--- |")
if (/^\s*\|[\s:|-]+\|\s*$/.test(line)) {
continue;
}
// Only process table rows
if (!line.trim().startsWith("|")) {
continue;
}
// Extract all backticked tokens
const tokens: string[] = [];
let match: RegExpExecArray | null;
BACKTICK_RE.lastIndex = 0;
while ((match = BACKTICK_RE.exec(line)) !== null) {
if (match[1]) {
const token = match[1].trim();
if (token) {
tokens.push(token);
}
}
}
// Skip rows with no tokens or only one token (need at least canonical)
if (tokens.length < 1) {
skippedRows++;
continue;
}
// Check if aliases cell contains "(Kein Alias)"
const hasNoAliases = /\(Kein Alias\)/i.test(line);
const canonical = tokens[0];
if (!canonical) {
skippedRows++;
continue;
}
const inverse = tokens.length >= 2 && tokens[1] ? tokens[1] : undefined;
// Extract aliases: all tokens after the first two, but only if not "(Kein Alias)"
const aliases: string[] = [];
if (!hasNoAliases && tokens.length > 2) {
for (let i = 2; i < tokens.length; i++) {
const alias = tokens[i];
if (alias) {
aliases.push(alias);
}
}
}
// Store canonical entry
byCanonical.set(canonical, {
canonical,
inverse,
aliases,
});
// Build alias-to-canonical mapping (case-insensitive keys)
for (const alias of aliases) {
if (alias) {
const lowerAlias = alias.toLowerCase();
if (!aliasToCanonical.has(lowerAlias)) {
aliasToCanonical.set(lowerAlias, canonical);
}
}
}
}
if (skippedRows > 0) {
console.warn(`parseEdgeVocabulary: Skipped ${skippedRows} rows with insufficient tokens`);
}
return {
byCanonical,
aliasToCanonical,
};
}
+20
View File
@@ -0,0 +1,20 @@
export type CanonicalEdgeType = string;
export interface EdgeTypeEntry {
canonical: CanonicalEdgeType;
inverse?: CanonicalEdgeType;
aliases: string[];
}
export interface EdgeVocabulary {
// key: canonical edge type
byCanonical: Map<CanonicalEdgeType, EdgeTypeEntry>;
// key: alias (lowercased) -> canonical
aliasToCanonical: Map<string, CanonicalEdgeType>;
}
export interface NormalizeResult {
raw: string;
canonical: CanonicalEdgeType | null;
inverse: CanonicalEdgeType | null;
}