flowcorpus

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package flowcorpus parses a curated flow corpus (corpus.jsonl) into CKV chunks. The corpus is the machine-loadable form of human-written flow docs: each record describes a step / flow / invariant in natural language (often Korean prose) tied to a precise file:line + symbol. Embedding that prose is the "human wording → exact code keyword" bridge — a Jira-style description ("수수료 위임이 어디서 검증되나?") retrieves the step that implements it.

Record types (one JSON object per line, discriminated by "type"):

flow       → ChunkFlowSpine    (embed = summary)
step       → ChunkFlowStep     (embed = prose + symbol + branch conditions)
invariant  → ChunkInvariant    (embed = statement + assumes + check; curated)
edge       → skipped (graph-only; step.calls already carries the relation)

Input contract: <go-stablenet>/.claude/docs/corpus/SCHEMA.md. Malformed or unknown records are counted and skipped with a warning (build_corpus.py is a best-effort markdown parser, so the caller should check the counts), never aborting the load.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AlignSteps

func AlignSteps(chunks []types.Chunk, code CodeIndex) (resolved, total int)

AlignSteps sets AlignedChunkID on every flow_step chunk to the code chunk whose [Start, End] range contains the step's line, and returns how many of the total flow steps resolved. When several code spans contain the line the tightest (smallest) one wins, so a step aligns to the innermost symbol rather than an enclosing block. A step whose line matches no span is left unaligned (the corpus drifted from the code) and simply not counted as resolved.

Types

type CodeIndex

type CodeIndex map[string][]CodeSpan

CodeIndex maps a repo-relative file path to its code chunks' line spans.

func (CodeIndex) Add

func (ix CodeIndex) Add(file string, start, end int, id string)

Add records a code chunk span under its file. Callers pass only real code chunks (a positive start line); header/whole-file chunks are poor alignment targets because they span the file and would shadow the containing symbol.

type CodeSpan

type CodeSpan struct {
	Start int
	End   int
	ID    string
}

CodeSpan is a code chunk's line range and ID — the alignment target for a flow step. Built from the source chunks of one index (symbol / function-split kinds), keyed by file.

type Stats

type Stats struct {
	Flows      int
	Steps      int
	Invariants int
	Edges      int // counted but not chunked (graph-only)
	Skipped    int // malformed / unknown-type records
	Warnings   []string
}

Stats reports what Load produced, so the build can log counts and the caller can sanity-check against the source (e.g. expected flow/step/invariant totals).

func Load

func Load(path, corpusRel string) ([]types.Chunk, Stats, error)

Load reads and parses the corpus file at path. corpusRel is the citation path stamped on fileless chunks (flow / invariant records carry no code location); steps cite their own file:line. corpusRel should be the corpus file's path relative to a docs root registered with the build so query-time citation enforcement can resolve it.

func Parse

func Parse(r io.Reader, corpusRel string) ([]types.Chunk, Stats, error)

Parse converts a corpus JSONL stream into chunks. See Load for corpusRel.

Jump to

Keyboard shortcuts

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