WeKnora deployment source with the reviewed wiki identity, summary and recovery fixes
Anydoc / anydoc parser engine (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
CLI / test (macos-latest / go 1.26) (push) Canceled after 0s
CLI / test (ubuntu-latest / go 1.26) (push) Canceled after 0s
CLI / test (windows-latest / go 1.26) (push) Canceled after 0s
Build and Push Docker Image / build-ui (push) Canceled after 0s
Build and Push Docker Image / build-docreader (push) Canceled after 0s
Build and Push Docker Image / build-sandbox (push) Canceled after 0s
Build and Push Docker Image / build-app (amd64, linux/amd64, ubuntu-latest) (push) Canceled after 0s
Build and Push Docker Image / build-app (arm64, linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-weknora) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (latest, advisory) (push) Canceled after 0s
Frontend / Test, type-check, and build (push) Canceled after 0s
Go Lint Cache / warm lint cache (.) (push) Canceled after 0s
Go Lint Cache / warm lint cache (cli) (push) Canceled after 0s
Go Lint Cache / warm lint cache (client) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.10) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.11) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.12) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.13) (push) Canceled after 0s
Build and Push Docker Image / merge (push) Canceled after 0s
Build & Publish (dsh-weknora) / Publish to npm (push) Canceled after 0s
Build & Publish (mcp-server) / Build sdist + wheel (push) Canceled after 0s
Build & Publish (mcp-server) / Publish to PyPI (push) Canceled after 0s
Anydoc / anydoc parser engine (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
CLI / test (macos-latest / go 1.26) (push) Canceled after 0s
CLI / test (ubuntu-latest / go 1.26) (push) Canceled after 0s
CLI / test (windows-latest / go 1.26) (push) Canceled after 0s
Build and Push Docker Image / build-ui (push) Canceled after 0s
Build and Push Docker Image / build-docreader (push) Canceled after 0s
Build and Push Docker Image / build-sandbox (push) Canceled after 0s
Build and Push Docker Image / build-app (amd64, linux/amd64, ubuntu-latest) (push) Canceled after 0s
Build and Push Docker Image / build-app (arm64, linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-weknora) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (latest, advisory) (push) Canceled after 0s
Frontend / Test, type-check, and build (push) Canceled after 0s
Go Lint Cache / warm lint cache (.) (push) Canceled after 0s
Go Lint Cache / warm lint cache (cli) (push) Canceled after 0s
Go Lint Cache / warm lint cache (client) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.10) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.11) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.12) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.13) (push) Canceled after 0s
Build and Push Docker Image / merge (push) Canceled after 0s
Build & Publish (dsh-weknora) / Publish to npm (push) Canceled after 0s
Build & Publish (mcp-server) / Build sdist + wheel (push) Canceled after 0s
Build & Publish (mcp-server) / Publish to PyPI (push) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
// Package chunker - heading_hierarchy.go tracks Markdown heading nesting so
|
||||
// that the heading-aware splitter (heading_splitter.go) can prepend a
|
||||
// breadcrumb like "# Top > ## Section > ### Subsection" to each chunk.
|
||||
//
|
||||
// Conceptually similar to header_tracker.go (which tracks table headers via
|
||||
// start/end hooks) but a Markdown heading does not have an explicit end —
|
||||
// it is ended by the next heading of equal or shallower depth. The hook
|
||||
// abstraction in header_tracker.go does not fit that pattern, so we model
|
||||
// it as an explicit level-stack.
|
||||
package chunker
|
||||
|
||||
import "strings"
|
||||
|
||||
// HeadingHierarchy maintains a stack of active Markdown headings indexed by
|
||||
// level (1..6). Pushing a level-N heading pops every entry of level >= N
|
||||
// because the previous siblings/descendants are no longer in scope.
|
||||
type HeadingHierarchy struct {
|
||||
// stack[i] holds the heading text for level i+1 (so stack[0] = H1).
|
||||
// Entries beyond the deepest active level are empty strings.
|
||||
stack [6]string
|
||||
depth int // current deepest active level (0 if no active heading)
|
||||
}
|
||||
|
||||
// NewHeadingHierarchy returns an empty hierarchy.
|
||||
func NewHeadingHierarchy() *HeadingHierarchy {
|
||||
return &HeadingHierarchy{}
|
||||
}
|
||||
|
||||
// Observe parses line and updates the hierarchy if line is a Markdown
|
||||
// heading. Returns the (level, headingText) when a heading was recognized,
|
||||
// or (0, "") otherwise. Lines that look like headings inside fenced code
|
||||
// blocks are NOT detected here — callers must avoid feeding code-block
|
||||
// content to Observe (the heading splitter does so).
|
||||
func (h *HeadingHierarchy) Observe(line string) (int, string) {
|
||||
m := MarkdownHeadingPattern.FindStringSubmatch(line)
|
||||
if m == nil {
|
||||
return 0, ""
|
||||
}
|
||||
level := len(m[1])
|
||||
if level < 1 || level > 6 {
|
||||
return 0, ""
|
||||
}
|
||||
heading := strings.TrimSpace(m[2])
|
||||
// Replace this level and clear deeper ones — siblings/descendants of
|
||||
// the previous heading at this level are no longer in scope.
|
||||
h.stack[level-1] = heading
|
||||
for i := level; i < 6; i++ {
|
||||
h.stack[i] = ""
|
||||
}
|
||||
if level > h.depth {
|
||||
h.depth = level
|
||||
} else {
|
||||
// Recompute depth: it might shrink if we just pushed a shallower heading.
|
||||
h.depth = 0
|
||||
for i := 0; i < 6; i++ {
|
||||
if h.stack[i] != "" {
|
||||
h.depth = i + 1
|
||||
}
|
||||
}
|
||||
}
|
||||
return level, heading
|
||||
}
|
||||
|
||||
// Breadcrumb returns the current heading path joined by " > ", e.g.
|
||||
// "Chapter 1 > Section 2 > Subsection a". Returns "" when no headings
|
||||
// are active.
|
||||
func (h *HeadingHierarchy) Breadcrumb() string {
|
||||
if h.depth == 0 {
|
||||
return ""
|
||||
}
|
||||
parts := make([]string, 0, h.depth)
|
||||
for i := 0; i < h.depth; i++ {
|
||||
if h.stack[i] != "" {
|
||||
parts = append(parts, h.stack[i])
|
||||
}
|
||||
}
|
||||
return strings.Join(parts, " > ")
|
||||
}
|
||||
|
||||
// BreadcrumbWithHashes returns the path with the original `#` prefixes,
|
||||
// suitable for embedding back into chunk content as a context header.
|
||||
// Example: "# Chapter 1\n## Section 2\n### Subsection a"
|
||||
func (h *HeadingHierarchy) BreadcrumbWithHashes() string {
|
||||
if h.depth == 0 {
|
||||
return ""
|
||||
}
|
||||
var sb strings.Builder
|
||||
for i := 0; i < h.depth; i++ {
|
||||
if h.stack[i] == "" {
|
||||
continue
|
||||
}
|
||||
if sb.Len() > 0 {
|
||||
sb.WriteByte('\n')
|
||||
}
|
||||
sb.WriteString(strings.Repeat("#", i+1))
|
||||
sb.WriteByte(' ')
|
||||
sb.WriteString(h.stack[i])
|
||||
}
|
||||
return sb.String()
|
||||
}
|
||||
|
||||
// Depth returns the current deepest active heading level.
|
||||
func (h *HeadingHierarchy) Depth() int { return h.depth }
|
||||
|
||||
// Reset clears all state.
|
||||
func (h *HeadingHierarchy) Reset() {
|
||||
for i := range h.stack {
|
||||
h.stack[i] = ""
|
||||
}
|
||||
h.depth = 0
|
||||
}
|
||||
Reference in New Issue
Block a user