Implement WP-26 features for Section-Types, Block-IDs, and Edge Suggestions
Node.js build / build (20.x) (push) Has been cancelled
Node.js build / build (22.x) (push) Has been cancelled

- Enhanced the interview configuration parsing to support section_type, block_id, and generate_block_id properties.
- Updated the renderer to incorporate Section-Types and Block-IDs, allowing for automatic edge suggestions during markdown rendering.
- Introduced new RenderOptions for improved handling of graph schema and vocabulary in the rendering process.
- Implemented tracking of Section-Info during the wizard flow, including updates for loop items and nested steps.
- Enhanced the InterviewWizardModal to support Block-ID selection for intra-note links, improving user experience and functionality.
This commit is contained in:
Lars committed 2026-01-27 11:18:56 +01:00
1 parent 3be7d617fe
commit b99416b67d
6 files changed
+1379 -122

No files matched your search

+68
View File
@@ -320,6 +320,40 @@ function parseStep(raw: Record<string, unknown>): InterviewStep | null {
step.prompt = raw.prompt.trim();
}
// WP-26: Parse section_type
if (typeof raw.section_type === "string" && raw.section_type.trim()) {
step.section_type = raw.section_type.trim();
}
// WP-26: Parse block_id
if (typeof raw.block_id === "string" && raw.block_id.trim()) {
step.block_id = raw.block_id.trim();
}
// WP-26: Parse generate_block_id
if (typeof raw.generate_block_id === "boolean") {
step.generate_block_id = raw.generate_block_id;
}
// WP-26: Parse references
if (Array.isArray(raw.references)) {
step.references = [];
for (const refRaw of raw.references) {
if (refRaw && typeof refRaw === "object") {
const ref = refRaw as Record<string, unknown>;
if (typeof ref.block_id === "string" && ref.block_id.trim()) {
const reference: { block_id: string; edge_type?: string } = {
block_id: ref.block_id.trim(),
};
if (typeof ref.edge_type === "string" && ref.edge_type.trim()) {
reference.edge_type = ref.edge_type.trim();
}
step.references.push(reference);
}
}
}
}
// Parse output.template
if (raw.output && typeof raw.output === "object") {
const output = raw.output as Record<string, unknown>;
@@ -363,6 +397,40 @@ function parseStep(raw: Record<string, unknown>): InterviewStep | null {
};
}
// WP-26: Parse section_type
if (typeof raw.section_type === "string" && raw.section_type.trim()) {
step.section_type = raw.section_type.trim();
}
// WP-26: Parse block_id
if (typeof raw.block_id === "string" && raw.block_id.trim()) {
step.block_id = raw.block_id.trim();
}
// WP-26: Parse generate_block_id
if (typeof raw.generate_block_id === "boolean") {
step.generate_block_id = raw.generate_block_id;
}
// WP-26: Parse references
if (Array.isArray(raw.references)) {
step.references = [];
for (const refRaw of raw.references) {
if (refRaw && typeof refRaw === "object") {
const ref = refRaw as Record<string, unknown>;
if (typeof ref.block_id === "string" && ref.block_id.trim()) {
const reference: { block_id: string; edge_type?: string } = {
block_id: ref.block_id.trim(),
};
if (typeof ref.edge_type === "string" && ref.edge_type.trim()) {
reference.edge_type = ref.edge_type.trim();
}
step.references.push(reference);
}
}
}
}
// Parse output.template
if (raw.output && typeof raw.output === "object") {
const output = raw.output as Record<string, unknown>;
+305
View File
@@ -0,0 +1,305 @@
/**
* Tests für WP-26 Interview-Wizard Renderer
* Prüft Section-Types, Block-IDs, automatische Edge-Vorschläge und Selbstreferenz-Prüfung
*/
import { describe, it, expect } from "vitest";
import { renderProfileToMarkdown, type RenderAnswers, type RenderOptions } from "./renderer";
import type { InterviewProfile } from "./types";
import type { GraphSchema, EdgeTypeHints } from "../mapping/graphSchema";
import { Vocabulary } from "../vocab/Vocabulary";
import { parseEdgeVocabulary } from "../vocab/parseEdgeVocabulary";
describe("WP-26 Interview Renderer", () => {
// Mock Vocabulary
const mockVocabularyText = `| System-Typ (Canonical) | Inverser Typ | Erlaubte Aliasse (User) | Beschreibung |
|------------------------|--------------|-------------------------|-------------|
| resulted_in | resulted_from| führt zu, bewirkt | Forward edge |
| resulted_from | resulted_in | stammt aus, kommt von | Inverse edge |
| related_to | related_to | verbunden mit | Bidirectional |`;
const mockVocabulary = new Vocabulary(parseEdgeVocabulary(mockVocabularyText));
// Mock GraphSchema
const mockGraphSchema: GraphSchema = {
schema: new Map<string, Map<string, EdgeTypeHints>>([
[
"experience",
new Map<string, EdgeTypeHints>([
[
"insight",
{
typical: ["resulted_in"],
prohibited: [],
},
],
]),
],
]),
};
const mockOptions: RenderOptions = {
graphSchema: mockGraphSchema,
vocabulary: mockVocabulary,
noteType: "experience",
};
it("sollte keine Selbstreferenz bei automatischen Edges generieren", () => {
const profile: InterviewProfile = {
version: "2.0",
frontmatterWhitelist: [],
key: "test",
label: "Test",
note_type: "experience",
steps: [
{
type: "capture_text",
key: "context",
section: "## Kontext",
section_type: "experience",
generate_block_id: true,
},
{
type: "capture_text",
key: "insight",
section: "## Einsicht",
section_type: "insight",
generate_block_id: true,
},
],
};
const answers: RenderAnswers = {
collectedData: new Map([
["context", "Kontext-Text"],
["insight", "Einsicht-Text"],
]),
loopContexts: new Map(),
};
const result = renderProfileToMarkdown(profile, answers, mockOptions);
// Prüfe, dass keine Selbstreferenz vorhanden ist
const contextSection = result.match(/## Kontext.*?## Einsicht/s)?.[0];
expect(contextSection).toBeDefined();
// Prüfe, dass keine Edge auf sich selbst zeigt
const selfReference = contextSection?.match(/\[\[#\^context\]\]/);
expect(selfReference).toBeNull();
// Prüfe, dass Edges generiert wurden
const edges = result.match(/> \[!edge\]/g);
expect(edges?.length).toBeGreaterThan(0);
});
it("sollte Edge-Types aus graph_schema verwenden", () => {
const profile: InterviewProfile = {
version: "2.0",
frontmatterWhitelist: [],
key: "test",
label: "Test",
note_type: "experience",
steps: [
{
type: "capture_text",
key: "experience",
section: "## Erfahrung",
section_type: "experience",
generate_block_id: true,
},
{
type: "capture_text",
key: "insight",
section: "## Einsicht",
section_type: "insight",
generate_block_id: true,
},
],
};
const answers: RenderAnswers = {
collectedData: new Map([
["experience", "Erfahrungs-Text"],
["insight", "Einsicht-Text"],
]),
loopContexts: new Map(),
};
const result = renderProfileToMarkdown(profile, answers, mockOptions);
// Debug: Zeige das Ergebnis
console.log("Render-Ergebnis:", result);
// Prüfe, dass Edges generiert wurden
const edges = result.match(/> \[!edge\]/g);
expect(edges?.length).toBeGreaterThan(0);
// Prüfe, dass "resulted_in" oder "resulted_from" verwendet wird (aus graph_schema)
// Falls graph_schema nicht verfügbar ist, wird "related_to" verwendet (Fallback)
const hasResultedEdge = result.match(/resulted_(in|from)/);
const hasRelatedEdge = result.match(/related_to/);
// Mindestens eine Edge sollte vorhanden sein
expect(hasResultedEdge || hasRelatedEdge).toBeTruthy();
// Wenn graph_schema verfügbar ist, sollte "resulted_in" oder "resulted_from" verwendet werden
if (mockOptions.graphSchema) {
expect(hasResultedEdge).toBeTruthy();
}
});
it("sollte Backlinks automatisch generieren", () => {
const profile: InterviewProfile = {
version: "2.0",
frontmatterWhitelist: [],
key: "test",
label: "Test",
note_type: "experience",
steps: [
{
type: "capture_text",
key: "context",
section: "## Kontext",
section_type: "experience",
generate_block_id: true,
},
{
type: "capture_text",
key: "insight",
section: "## Einsicht",
section_type: "insight",
generate_block_id: true,
},
],
};
const answers: RenderAnswers = {
collectedData: new Map([
["context", "Kontext-Text"],
["insight", "Einsicht-Text"],
]),
loopContexts: new Map(),
};
const result = renderProfileToMarkdown(profile, answers, mockOptions);
// Prüfe, dass beide Edge-Types vorhanden sind (Forward und Backward)
const forwardEdge = result.match(/resulted_in/);
const backwardEdge = result.match(/resulted_from/);
expect(forwardEdge).toBeDefined();
expect(backwardEdge).toBeDefined();
});
it("sollte keine Selbstreferenz bei expliziten Referenzen erlauben", () => {
const profile: InterviewProfile = {
version: "2.0",
frontmatterWhitelist: [],
key: "test",
label: "Test",
note_type: "experience",
steps: [
{
type: "capture_text",
key: "context",
section: "## Kontext",
section_type: "experience",
block_id: "context",
references: [
{
block_id: "context", // Selbstreferenz - sollte verhindert werden
edge_type: "related_to",
},
],
},
],
};
const answers: RenderAnswers = {
collectedData: new Map([
["context", "Kontext-Text"],
]),
loopContexts: new Map(),
};
const result = renderProfileToMarkdown(profile, answers, mockOptions);
// Prüfe, dass keine Selbstreferenz generiert wurde
const selfReference = result.match(/\[\[#\^context\]\]/);
// Sollte null sein, da Selbstreferenz verhindert wird
expect(selfReference).toBeNull();
});
it("sollte Section-Type-Callout direkt nach Heading platzieren", () => {
const profile: InterviewProfile = {
version: "2.0",
frontmatterWhitelist: [],
key: "test",
label: "Test",
note_type: "experience",
steps: [
{
type: "capture_text",
key: "context",
section: "## Kontext",
section_type: "experience",
generate_block_id: true,
},
],
};
const answers: RenderAnswers = {
collectedData: new Map([
["context", "Kontext-Text"],
]),
loopContexts: new Map(),
};
const result = renderProfileToMarkdown(profile, answers, mockOptions);
// Prüfe, dass Section-Type-Callout direkt nach Heading steht
const sectionPattern = /## Kontext.*?\n> \[!section\] experience/s;
expect(result).toMatch(sectionPattern);
});
it("sollte Edges am Ende der Sektion platzieren", () => {
const profile: InterviewProfile = {
version: "2.0",
frontmatterWhitelist: [],
key: "test",
label: "Test",
note_type: "experience",
steps: [
{
type: "capture_text",
key: "context",
section: "## Kontext",
section_type: "experience",
generate_block_id: true,
},
{
type: "capture_text",
key: "insight",
section: "## Einsicht",
section_type: "insight",
generate_block_id: true,
},
],
};
const answers: RenderAnswers = {
collectedData: new Map([
["context", "Kontext-Text"],
["insight", "Einsicht-Text"],
]),
loopContexts: new Map(),
};
const result = renderProfileToMarkdown(profile, answers, mockOptions);
// Prüfe, dass Edges am Ende der Einsicht-Sektion stehen (nach dem Text)
const insightSection = result.match(/## Einsicht.*?Einsicht-Text\n\n(> \[!edge\].*)/s)?.[1];
expect(insightSection).toBeDefined();
expect(insightSection).toMatch(/> \[!edge\]/);
});
});
+404 -48
View File
@@ -1,27 +1,68 @@
/**
* Markdown renderer for interview profiles.
* Converts collected answers into markdown output based on profile configuration.
* WP-26: Erweitert um Section-Types, Block-IDs und automatische Edge-Vorschläge.
*/
import type { InterviewProfile, InterviewStep, CaptureTextStep, CaptureTextLineStep, CaptureFrontmatterStep, LoopStep, EntityPickerStep } from "./types";
import type { SectionInfo } from "./wizardState";
import type { GraphSchema } from "../mapping/graphSchema";
import type { Vocabulary } from "../vocab/Vocabulary";
import { slugify } from "./slugify";
import { getHints } from "../mapping/graphSchema";
export interface RenderAnswers {
collectedData: Map<string, unknown>;
loopContexts: Map<string, unknown[]>;
// WP-26: Optional - Section-Sequenz für automatische Edge-Vorschläge
sectionSequence?: SectionInfo[];
}
// WP-26: Render-Optionen für Section-Types und Edge-Vorschläge
export interface RenderOptions {
graphSchema?: GraphSchema | null;
vocabulary?: Vocabulary | null;
noteType?: string; // Fallback für effective_type
}
/**
* Render profile answers to markdown string.
* Deterministic and testable.
* WP-26: Erweitert um Section-Types, Block-IDs und automatische Edge-Vorschläge.
*/
export function renderProfileToMarkdown(
profile: InterviewProfile,
answers: RenderAnswers
answers: RenderAnswers,
options?: RenderOptions
): string {
const output: string[] = [];
// WP-26: Verwende übergebene Section-Sequenz oder erstelle neue
// Die Section-Sequenz wird während des interaktiven Wizard-Durchlaufs getrackt
const sectionSequence: SectionInfo[] = answers.sectionSequence ? [...answers.sectionSequence] : [];
const generatedBlockIds = new Map<string, SectionInfo>();
// WP-26: Wenn Section-Sequenz übergeben wurde, fülle generatedBlockIds aus der Sequenz
if (answers.sectionSequence && answers.sectionSequence.length > 0) {
for (const sectionInfo of answers.sectionSequence) {
if (sectionInfo.blockId) {
generatedBlockIds.set(sectionInfo.blockId, sectionInfo);
}
}
}
// WP-26: Track Section-Sequenz während des Renderns (für Steps, die noch nicht getrackt wurden)
for (const step of profile.steps) {
const stepOutput = renderStep(step, answers);
const stepOutput = renderStep(
step,
answers,
{
profile,
sectionSequence,
generatedBlockIds,
options: options || {},
}
);
if (stepOutput) {
output.push(stepOutput);
}
@@ -30,20 +71,33 @@ export function renderProfileToMarkdown(
return output.join("\n\n").trim();
}
// WP-26: Render-Kontext für Section-Types und Block-IDs
interface RenderContext {
profile: InterviewProfile;
sectionSequence: SectionInfo[];
generatedBlockIds: Map<string, SectionInfo>;
options: RenderOptions;
}
/**
* Render a single step to markdown.
* WP-26: Erweitert um RenderContext für Section-Types und Block-IDs.
*/
function renderStep(step: InterviewStep, answers: RenderAnswers): string | null {
function renderStep(
step: InterviewStep,
answers: RenderAnswers,
context: RenderContext
): string | null {
switch (step.type) {
case "capture_text":
return renderCaptureText(step, answers);
return renderCaptureText(step, answers, context);
case "capture_text_line":
return renderCaptureTextLine(step, answers);
return renderCaptureTextLine(step, answers, context);
case "capture_frontmatter":
// Frontmatter is handled separately, skip here
return null;
case "loop":
return renderLoop(step, answers);
return renderLoop(step, answers, context);
case "entity_picker":
return renderEntityPicker(step, answers);
case "instruction":
@@ -58,8 +112,13 @@ function renderStep(step: InterviewStep, answers: RenderAnswers): string | null
/**
* Render capture_text step.
* WP-26: Erweitert um Section-Types, Block-IDs und Edge-Vorschläge.
*/
function renderCaptureText(step: CaptureTextStep, answers: RenderAnswers): string | null {
function renderCaptureText(
step: CaptureTextStep,
answers: RenderAnswers,
context: RenderContext
): string | null {
const value = answers.collectedData.get(step.key);
if (!value || String(value).trim() === "") {
return null;
@@ -67,18 +126,66 @@ function renderCaptureText(step: CaptureTextStep, answers: RenderAnswers): strin
const text = String(value);
// WP-26: Block-ID-Generierung
let blockId: string | null = null;
if (step.block_id) {
blockId = step.block_id;
} else if (step.generate_block_id) {
blockId = slugify(step.key);
}
// WP-26: Heading mit Block-ID erweitern
let heading = step.section || "";
if (heading && blockId) {
// Füge Block-ID zu Heading hinzu: "## Heading" -> "## Heading ^block-id"
heading = heading.replace(/^(\s*#{1,6}\s+)(.+)$/, `$1$2 ^${blockId}`);
}
// WP-26: Section-Type-Callout generieren (direkt nach Heading)
const sectionTypeCallout = step.section_type
? `> [!section] ${step.section_type}`
: "";
// WP-26: Section-Info für Tracking
const sectionInfo: SectionInfo = {
stepKey: step.key,
sectionType: step.section_type || null,
heading: heading || step.key,
blockId: blockId,
noteType: context.options.noteType || context.profile.note_type,
};
// WP-26: Block-ID tracken
if (blockId) {
context.generatedBlockIds.set(blockId, sectionInfo);
}
// WP-26: Section-Sequenz aktualisieren (nur wenn Section vorhanden)
if (step.section) {
context.sectionSequence.push(sectionInfo);
}
// WP-26: Referenzen generieren (am Ende der Sektion)
const references = renderReferences(step.references || [], context, sectionInfo);
// WP-26: Automatische Edge-Vorschläge generieren (am Ende der Sektion)
const autoEdges = renderAutomaticEdges(sectionInfo, context);
// Use template if provided
if (step.output?.template) {
return renderTemplate(step.output.template, {
const templateText = renderTemplate(step.output.template, {
text,
field: step.key,
value: text,
});
// WP-26: Template mit Heading, Section-Type und Edges kombinieren
return combineSectionParts(heading, sectionTypeCallout, templateText, references, autoEdges);
}
// Default: use section if provided, otherwise just the text
if (step.section) {
return `${step.section}\n\n${text}`;
return combineSectionParts(heading, sectionTypeCallout, text, references, autoEdges);
}
return text;
@@ -86,8 +193,13 @@ function renderCaptureText(step: CaptureTextStep, answers: RenderAnswers): strin
/**
* Render capture_text_line step.
* WP-26: Erweitert um Section-Types, Block-IDs und Edge-Vorschläge.
*/
function renderCaptureTextLine(step: CaptureTextLineStep, answers: RenderAnswers): string | null {
function renderCaptureTextLine(
step: CaptureTextLineStep,
answers: RenderAnswers,
context: RenderContext
): string | null {
const value = answers.collectedData.get(step.key);
if (!value || String(value).trim() === "") {
return null;
@@ -110,14 +222,98 @@ function renderCaptureTextLine(step: CaptureTextLineStep, answers: RenderAnswers
}
}
// WP-26: Block-ID-Generierung
let blockId: string | null = null;
if (step.block_id) {
blockId = step.block_id;
} else if (step.generate_block_id) {
blockId = slugify(step.key);
}
// WP-26: Heading mit Block-ID erweitern (wenn heading_prefix vorhanden)
let heading = "";
if (headingPrefix) {
heading = headingPrefix + text;
if (blockId) {
// Füge Block-ID zu Heading hinzu
heading = heading.replace(/^(\s*#{1,6}\s+)(.+)$/, `$1$2 ^${blockId}`);
}
}
// WP-26: Section-Type-Callout generieren (direkt nach Heading)
const sectionTypeCallout = step.section_type
? `> [!section] ${step.section_type}`
: "";
// WP-26: Section-Info für Tracking (nur wenn Heading vorhanden)
if (headingPrefix) {
const sectionInfo: SectionInfo = {
stepKey: step.key,
sectionType: step.section_type || null,
heading: heading || text,
blockId: blockId,
noteType: context.options.noteType || context.profile.note_type,
};
// WP-26: Block-ID tracken
if (blockId) {
context.generatedBlockIds.set(blockId, sectionInfo);
}
// WP-26: Section-Sequenz aktualisieren
context.sectionSequence.push(sectionInfo);
}
// WP-26: Section-Info für Tracking (nur wenn Heading vorhanden)
let sectionInfo: SectionInfo | null = null;
if (headingPrefix) {
sectionInfo = {
stepKey: step.key,
sectionType: step.section_type || null,
heading: heading || text,
blockId: blockId,
noteType: context.options.noteType || context.profile.note_type,
};
// WP-26: Block-ID tracken
if (blockId) {
context.generatedBlockIds.set(blockId, sectionInfo);
}
// WP-26: Section-Sequenz aktualisieren
context.sectionSequence.push(sectionInfo);
}
// WP-26: Referenzen generieren (am Ende der Sektion)
const references = sectionInfo
? renderReferences(step.references || [], context, sectionInfo)
: "";
// WP-26: Automatische Edge-Vorschläge generieren (nur wenn Heading vorhanden)
const autoEdges = sectionInfo
? renderAutomaticEdges(sectionInfo, context)
: "";
// Use template if provided
if (step.output?.template) {
return renderTemplate(step.output.template, {
const templateText = renderTemplate(step.output.template, {
text: headingPrefix + text,
field: step.key,
value: headingPrefix + text,
heading_level: headingLevel ? String(headingLevel) : "",
});
// WP-26: Template mit Heading, Section-Type und Edges kombinieren (wenn Heading vorhanden)
if (headingPrefix) {
return combineSectionParts(heading, sectionTypeCallout, "", references, autoEdges);
}
return templateText;
}
// WP-26: Wenn Heading vorhanden, mit Section-Type und Edges kombinieren
if (headingPrefix) {
return combineSectionParts(heading, sectionTypeCallout, "", references, autoEdges);
}
// Default: text with heading prefix if configured
@@ -175,16 +371,23 @@ function renderCaptureFrontmatter(step: CaptureFrontmatterStep, answers: RenderA
/**
* Render loop step (recursive, supports arbitrary nesting depth).
* WP-26: Erweitert um RenderContext für Section-Types und Block-IDs.
*/
function renderLoop(step: LoopStep, answers: RenderAnswers): string | null {
return renderLoopRecursive(step, answers, 0);
function renderLoop(step: LoopStep, answers: RenderAnswers, context: RenderContext): string | null {
return renderLoopRecursive(step, answers, context, 0);
}
/**
* Recursive helper to render loop items with nested steps.
* Supports arbitrary nesting depth (no hard limit, but practical limits apply due to stack size).
* WP-26: Erweitert um RenderContext für Section-Types und Block-IDs.
*/
function renderLoopRecursive(step: LoopStep, answers: RenderAnswers, depth: number): string | null {
function renderLoopRecursive(
step: LoopStep,
answers: RenderAnswers,
context: RenderContext,
depth: number
): string | null {
// Safety check: prevent infinite recursion (practical limit: 100 levels)
if (depth > 100) {
console.warn(`Loop nesting depth ${depth} exceeds practical limit, stopping recursion`);
@@ -214,49 +417,39 @@ function renderLoopRecursive(step: LoopStep, answers: RenderAnswers, depth: numb
const text = String(fieldValue);
const captureStep = nestedStep as CaptureTextStep;
// Use template if provided
if (captureStep.output?.template) {
itemParts.push(renderTemplate(captureStep.output.template, {
text,
field: nestedStep.key,
value: text,
}));
} else {
// Default: just the text
itemParts.push(text);
// WP-26: Verwende erweiterte renderCaptureText Funktion
const rendered = renderCaptureText(captureStep, {
collectedData: new Map([[nestedStep.key, fieldValue]]),
loopContexts: answers.loopContexts,
}, context);
if (rendered) {
itemParts.push(rendered);
}
}
} else if (nestedStep.type === "capture_text_line") {
if (fieldValue && String(fieldValue).trim()) {
const text = String(fieldValue);
const captureStep = nestedStep as CaptureTextLineStep;
// Get heading level if configured (for nested loops, check in item data)
// WP-26: Erstelle temporäres collectedData mit allen Item-Daten
const itemData = new Map<string, unknown>();
itemData.set(nestedStep.key, fieldValue);
// Füge heading_level hinzu falls vorhanden
const headingLevelKey = `${nestedStep.key}_heading_level`;
const headingLevel = (item as Record<string, unknown>)[headingLevelKey];
let headingPrefix = "";
if (captureStep.heading_level?.enabled) {
if (typeof headingLevel === "number") {
const level = Math.max(1, Math.min(6, headingLevel));
headingPrefix = "#".repeat(level) + " ";
} else if (captureStep.heading_level.default) {
// Fallback to default if not set in item
const level = Math.max(1, Math.min(6, captureStep.heading_level.default));
headingPrefix = "#".repeat(level) + " ";
}
if (headingLevel !== undefined) {
itemData.set(headingLevelKey, headingLevel);
}
// Use template if provided
if (captureStep.output?.template) {
itemParts.push(renderTemplate(captureStep.output.template, {
text: headingPrefix + text,
field: nestedStep.key,
value: headingPrefix + text,
heading_level: headingLevel ? String(headingLevel) : (captureStep.heading_level?.default ? String(captureStep.heading_level.default) : ""),
}));
} else {
// Default: text with heading prefix if configured
itemParts.push(headingPrefix + text);
// WP-26: Verwende erweiterte renderCaptureTextLine Funktion
const rendered = renderCaptureTextLine(captureStep, {
collectedData: itemData,
loopContexts: answers.loopContexts,
}, context);
if (rendered) {
itemParts.push(rendered);
}
}
} else if (nestedStep.type === "capture_frontmatter") {
@@ -287,7 +480,7 @@ function renderLoopRecursive(step: LoopStep, answers: RenderAnswers, depth: numb
nestedAnswers.loopContexts.set(nestedLoopStep.key, fieldValue);
// Recursively render the nested loop
const nestedOutput = renderLoopRecursive(nestedLoopStep, nestedAnswers, depth + 1);
const nestedOutput = renderLoopRecursive(nestedLoopStep, nestedAnswers, context, depth + 1);
if (nestedOutput) {
itemParts.push(nestedOutput);
}
@@ -339,3 +532,166 @@ function renderTemplate(template: string, tokens: { text: string; field: string;
return result;
}
// WP-26: Helper-Funktionen für Section-Types und Block-IDs
/**
* Kombiniert Heading, Section-Type-Callout, Content und Edges zu einer Section.
* Formatierungsregel: Section-Type direkt nach Heading, Edges am Ende.
*/
function combineSectionParts(
heading: string,
sectionTypeCallout: string,
content: string,
references: string,
autoEdges: string
): string {
const parts: string[] = [];
if (heading) {
parts.push(heading);
}
if (sectionTypeCallout) {
parts.push(sectionTypeCallout);
}
if (content) {
parts.push(content);
}
// WP-26: Edges am Ende der Sektion (Referenzen + automatische Edges)
const edges = [references, autoEdges].filter(e => e.trim()).join("\n");
if (edges) {
parts.push(edges);
}
return parts.join("\n\n");
}
/**
* Generiert Edge-Callouts für explizite Referenzen.
* Format: > [!edge] <edge_type>\n> [[#^block-id]]
*/
function renderReferences(
references: Array<{ block_id: string; edge_type?: string }>,
context: RenderContext,
currentSection: SectionInfo
): string {
if (!references || references.length === 0) {
return "";
}
const edgeCallouts: string[] = [];
for (const ref of references) {
// Prüfe, ob Block-ID existiert
if (!context.generatedBlockIds.has(ref.block_id)) {
console.warn(`[WP-26] Block-ID "${ref.block_id}" nicht gefunden für Referenz`);
continue;
}
// WP-26: Prüfe auf Selbstreferenz
if (ref.block_id === currentSection.blockId) {
console.warn(`[WP-26] Selbstreferenz verhindert: Block-ID "${ref.block_id}" zeigt auf sich selbst`);
continue;
}
const edgeType = ref.edge_type || "related_to";
edgeCallouts.push(`> [!edge] ${edgeType}`);
edgeCallouts.push(`> [[#^${ref.block_id}]]`);
}
return edgeCallouts.join("\n");
}
/**
* Generiert automatische Edge-Vorschläge zwischen Sections.
* Verwendet graph_schema.md für typische Edge-Types und edge_vocabulary.md für inverse Edges.
*
* Formatierungsregel: Edges werden am Ende der aktuellen Section eingefügt.
* Forward-Edge: prevSection -> currentSection (in aktueller Section)
* Rückwärts-Edge: currentSection -> prevSection (in aktueller Section, inverser Edge-Type)
*/
function renderAutomaticEdges(
currentSection: SectionInfo,
context: RenderContext
): string {
// Nur wenn aktuelle Section eine Block-ID hat
if (!currentSection.blockId) {
return "";
}
// Nur wenn es vorherige Sections gibt
if (context.sectionSequence.length <= 1) {
return "";
}
// Aktuelle Section ist die letzte in der Sequenz
// Wir generieren Edges von allen vorherigen Sections zur aktuellen Section
const prevSections = context.sectionSequence.slice(0, -1);
const edgeCallouts: string[] = [];
const { graphSchema, vocabulary } = context.options;
for (const prevSection of prevSections) {
// Nur wenn vorherige Section auch eine Block-ID hat
if (!prevSection.blockId) {
continue;
}
// WP-26: Prüfe auf Selbstreferenz (sollte nicht vorkommen, aber sicherheitshalber prüfen)
if (prevSection.blockId === currentSection.blockId) {
console.warn(`[WP-26] Selbstreferenz verhindert: Block-ID "${prevSection.blockId}" zeigt auf sich selbst`);
continue;
}
// Ermittle effective_types
const prevType = prevSection.sectionType || prevSection.noteType;
const currentType = currentSection.sectionType || currentSection.noteType;
// Lookup in graph_schema.md: prevType -> currentType
let forwardEdgeType: string | null = null;
if (graphSchema && prevType && currentType) {
const hints = getHints(graphSchema, prevType, currentType);
if (hints.typical.length > 0) {
forwardEdgeType = hints.typical[0]; // Erster typischer Edge-Type aus graph_schema
} else {
// Debug: Log wenn keine typischen Edges gefunden wurden
console.debug(`[WP-26] Keine typischen Edges gefunden für ${prevType} -> ${currentType}`);
}
}
// Fallback: related_to
if (!forwardEdgeType) {
forwardEdgeType = "related_to";
}
// WP-26: Automatische Edge-Vorschläge
// Wir generieren beide Richtungen:
// 1. Forward-Edge: prevSection -> currentSection (mit originalem Edge-Type)
// 2. Rückwärts-Edge: currentSection -> prevSection (mit inversem Edge-Type)
//
// Beide Edges werden in der aktuellen Section eingefügt und zeigen zur prevSection
// Der Backlink wird automatisch mitgesetzt
// Rückwärts-Edge: currentSection -> prevSection (mit inversem Edge-Type)
let inverseEdgeType: string | null = null;
if (vocabulary) {
inverseEdgeType = vocabulary.getInverse(forwardEdgeType);
}
// Generiere Rückwärts-Edge (currentSection -> prevSection)
if (inverseEdgeType) {
edgeCallouts.push(`> [!edge] ${inverseEdgeType}`);
edgeCallouts.push(`> [[#^${prevSection.blockId}]]`);
}
// Generiere Forward-Edge als Backlink (prevSection -> currentSection)
// Diese Edge beschreibt die Beziehung von prevSection zu currentSection
edgeCallouts.push(`> [!edge] ${forwardEdgeType}`);
edgeCallouts.push(`> [[#^${prevSection.blockId}]]`);
}
return edgeCallouts.join("\n");
}
+16
View File
@@ -76,6 +76,14 @@ export interface CaptureTextStep {
required?: boolean;
section?: string; // Markdown section header (e.g., "## 🧩 Erlebnisse")
prompt?: string; // Optional prompt text
// WP-26: Section-Type und Block-ID Support
section_type?: string; // Optional: Section-Type (z.B. "experience", "insight")
block_id?: string; // Optional: Explizite Block-ID (z.B. "sit")
generate_block_id?: boolean; // Optional: Automatische Block-ID-Generierung aus Step-Key
references?: Array<{ // Optional: Referenzen zu vorherigen Sections
block_id: string; // Block-ID der referenzierten Section
edge_type?: string; // Optional: Vorgeschlagener Edge-Type
}>;
output?: {
template?: string; // Template with tokens: {text}, {field}, {value}
};
@@ -91,6 +99,14 @@ export interface CaptureTextLineStep {
enabled?: boolean; // Show heading level selector (default: false)
default?: number; // Default heading level 1-6 (default: 2)
};
// WP-26: Section-Type und Block-ID Support
section_type?: string; // Optional: Section-Type (z.B. "experience", "insight")
block_id?: string; // Optional: Explizite Block-ID (z.B. "sit")
generate_block_id?: boolean; // Optional: Automatische Block-ID-Generierung aus Step-Key
references?: Array<{ // Optional: Referenzen zu vorherigen Sections
block_id: string; // Block-ID der referenzierten Section
edge_type?: string; // Optional: Vorgeschlagener Edge-Type
}>;
output?: {
template?: string; // Template with tokens: {text}, {field}, {value}, {heading_level}
};
+3
View File
@@ -50,6 +50,9 @@ export function createWizardState(profile: InterviewProfile): WizardState {
patches: [],
activeLoopPath: [], // Start at top level
pendingEdgeAssignments: [], // Start with empty pending assignments
// WP-26: Initialize Section-Type und Block-ID Tracking
generatedBlockIds: new Map(),
sectionSequence: [],
};
}