wiki

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 18, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractWikilinks(body string) []string

ExtractWikilinks parses markdown body and returns the distinct [[target]] references in the page (excluding embedded resources like ![[img.png]]). Header fragments ([[Page#Section]]) reduce to the page target.

func NewQueryTool

func NewQueryTool(deps ToolsDeps, agentID string) types.Tool

NewQueryTool returns the wiki_query tool: semantic search over the agent's wiki pages + interest points, with keyword fallback.

func NewReviewTool

func NewReviewTool(deps ToolsDeps, agentID, lang string) types.Tool

NewReviewTool returns the review tool: the agent MUST call it before the formal write. It is strictly read-only — it semantic-searches existing wiki pages relevant to the draft, then asks the LLM to spot contradictions / duplicates / stale references and propose edits. It returns a suggestion list; the main agent decides what to adopt. lang is the output language for the review prompt.

func NewTagsTool

func NewTagsTool(deps ToolsDeps, agentID string) types.Tool

NewTagsTool returns the wiki_tags tool: a read-only listing of all tags already used by this agent (with usage counts). The agent consults it before writing so it reuses the existing tag taxonomy instead of inventing near-duplicate tags.

func NewVerifyClaimsTool

func NewVerifyClaimsTool(deps ToolsDeps, lang string) types.Tool

NewVerifyClaimsTool returns the verify_claims tool: the agent calls it during writing to fact-check a draft statement against the web. It gathers web evidence (when a Searcher is wired) then asks the LLM for a verdict. Degrades to a JSON unknown verdict rather than erroring. lang is the output language for the audit prompt.

func NewWriteTool

func NewWriteTool(deps ToolsDeps, agentID string) types.Tool

NewWriteTool returns the wiki_write tool: creates or updates a wiki page (with claims, edges, and embedding) in the SQLite store. Enforces edge rules before writing (target exists / no self-ref / max 8 / dedup / kind).

Types

type ArchivedInfo

type ArchivedInfo struct {
	ID               string
	Title            string
	Outlinks         []store.Edge
	ReplacementID    string
	ReplacementTitle string
	Superseded       bool // true: replacement chain (sequel) exists; false: pure deletion
}

ArchivedInfo is an archived interest point with the detail the reconcile stage needs: its title, its outbound edges (original outlinks), and — when it was superseded rather than deleted — the live replacement id/title (replacement chain).

type ClaimLLM

type ClaimLLM interface {
	ChatJSON(ctx context.Context, messages []llm.Message, out any) error
}

ClaimLLM is the chat surface verify_claims needs (implemented by *llm.Client). Kept narrow for test fakes.

type Compiler

type Compiler interface {
	Compile(ctx context.Context, agentID string, pts []store.InterestPoint, msgs []types.Message) ([]string, error)
	// RebuildEdges regenerates adjacency for the given touched page ids only
	// (incremental), unlike a full re-scan of every agent page.
	RebuildEdges(ctx context.Context, agentID string, touched []string) error
	// ReconcileRelated propagates structural changes (written/updated pages,
	// archived interest points) to related pages within maxHops, in batches.
	ReconcileRelated(ctx context.Context, agentID string, in ReconcileInput, maxHops, batchSize int) error
}

Compiler is the domain interface: write wiki pages from interest points + transcript via the agent loop, then rebuild edges. Compile returns the ids of pages touched this run (new/updated) so the caller can reconcile related pages.

type Embedder

type Embedder interface {
	Embed(ctx context.Context, text string) ([]float32, error)
}

type ProviderFactory

type ProviderFactory func(ctx context.Context) (*provider.Provider, error)

ProviderFactory builds the my-agent-core provider from config (used by the WikiWriter agent loop). Returns nil when the LLM is not configured.

type ReconcileInput

type ReconcileInput struct {
	TouchedPages   []string // wiki page ids written/updated this run
	ArchivedPoints []string // interest point ids archived (deleted/superseded) this run
}

ReconcileInput lists what changed this pipeline run so the reconcile stage knows which pages to propagate changes to.

type ToolsDeps

type ToolsDeps struct {
	Store    store.Store
	Vec      vec.VectorIndex
	Embedder Embedder
	Search   websearch.Searcher
	LLM      ClaimLLM
}

ToolsDeps is everything the wiki tools need beyond the agent loop. Search/LLM are optional: when absent, verify_claims degrades gracefully.

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

Writer runs the SQLite-backed WikiWriter: for each interest point it spawns a dedicated my-agent-core agent armed with wiki_query / verify_claims / review / wiki_write tools to persist knowledge (single-point + evidence + conversation, serial loops).

func NewWriter

func NewWriter(deps ToolsDeps, prov ProviderFactory, lang string, verifyClaims bool) *Writer

NewWriter builds a Writer. deps carries store/vec/embedder/llm/searcher; prov builds the LLM provider lazily per call so tests can inject a fake. lang is the output language hint injected into the system prompt (default "English").

func (*Writer) Compile

func (w *Writer) Compile(ctx context.Context, agentID string, pts []store.InterestPoint, msgs []types.Message) ([]string, error)

Compile writes one wiki page per interest point via dedicated agent loops, run concurrently (bounded by maxCompileConcurrency). Each point's prompt carries its evidence, the exact conversation segment (by TurnRange), and a pre-looked-up related-page summary. Returns the page ids touched this run.

func (*Writer) RebuildEdges

func (w *Writer) RebuildEdges(ctx context.Context, agentID string, touched []string) error

RebuildEdges regenerates the adjacency table from the body wikilinks of the given touched pages (incremental: only pages written this run). It batches all store reads/writes so cost scales with the touched set, not the whole wiki. (Contradictions are persisted separately by service.persistContradictions, pipeline step 4.)

func (*Writer) ReconcileRelated

func (w *Writer) ReconcileRelated(ctx context.Context, agentID string, in ReconcileInput, maxHops, batchSize int) error

ReconcileRelated propagates a structural change to related wiki pages within maxHops hops (default 3). It collects the related-page subgraph (outlinks/backlinks/has_page), then dispatches batches of up to batchSize pages to a unified agent loop (wiki_query + wiki_write only — no review) that performs cascade archive / contradiction closure / content sync. Archived interest points are classified as superseded (has a sequel replacement link) or deleted (pure archive): the superseded ones get a code-level fallback substitution (marking the old concept page superseded and rewriting [[wikilinks]]) plus a prompt hint; deleted ones only surface their original outlinks in the prompt.

func (*Writer) SetTracker added in v0.2.0

func (w *Writer) SetTracker(t *usage.Tracker)

SetTracker wires an optional usage tracker; per-turn token usage from the agent loop is accumulated into it.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL