reader

package
v0.20.8 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package reader holds the reader feature's filesystem scope and confinement rules — which paths a session's reader may list and serve — independent of HTTP handling (kb:spec/reader). Pure filesystem logic, like internal/locate: it imports nothing from internal/server, internal/session or internal/claudecode. Features: reader.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ListMarkdown

func ListMarkdown(ctx context.Context, dir string, gitFiles ListFilesFunc) (paths []string, listing string, truncated bool, gitErr error)

ListMarkdown lists every `.md` (case-insensitive) file under dir: gitFiles's (typically gitutil.ListFiles) `git ls-files -co --exclude-standard` listing when dir is a git checkout, filtered to `.md`, or a bounded dot-directory-skipping walk otherwise (kb:spec/reader). A git failure (not a checkout, or a real error) is not itself fatal — ListMarkdown falls back to the walk and returns the git error as gitErr solely so the caller can log it; the walk's own result is never an error.

func WalkMarkdown

func WalkMarkdown(dir string) (paths []string, listing string, truncated bool)

WalkMarkdown lists every `.md` (case-insensitive) file under dir by walking it directly — ListMarkdown's fallback when dir isn't a git checkout, or the git query failed.

Types

type ListFilesFunc

type ListFilesFunc func(ctx context.Context, dir string) ([]string, error)

ListFilesFunc lists the files git sees under dir — ListMarkdown's consumer-side seam over gitutil.ListFiles (docs/conventions.md § Testing): production is gitutil.ListFiles, callers fake a neutral file list at this seam rather than git's own byte stream, since git's argv is gitutil's concern, not this package's.

type Scope

type Scope struct {
	Dir      string
	PlanPath string
}

Scope is one session's reader domain: the directory whose markdown may be listed and served, and the plan path served alongside it even though it usually sits outside Dir (kb:spec/reader). An empty PlanPath means no plan is bound yet.

func (Scope) Confine

func (s Scope) Confine(requested string) (string, bool)

Confine reports whether requested may be served from this scope, and its symlink-resolved form when so (kb:spec/reader's confinement rule): after filepath.EvalSymlinks of both s.Dir and requested, requested must sit under s.Dir and end in `.md` (case-insensitive), or equal the resolved s.PlanPath. Existence/directory- ness beyond symlink resolution is the caller's job (a Stat after Confine, distinguishing 404 from 413).

func (Scope) PathQualifies

func (s Scope) PathQualifies(path string) bool

PathQualifies is the change-signal's scope test (kb:adr/reader-change-signal-is-the-write-hook): after filepath.Clean, path sits lexically under s.Dir and ends in `.md` (case-insensitive), or equals s.PlanPath — no symlink resolution (that confinement belongs to serving, in Confine, not to the change signal).

type WriteLog

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

WriteLog is the daemon's in-memory record of routed writes, per session — forgotten on daemon restart, like shells: nothing here is written to disk. Record is called from internal/server's single ingest worker; Get and Forget are called from HTTP handlers and session removal. mu guards bySession against that concurrent access.

func NewWriteLog

func NewWriteLog() *WriteLog

NewWriteLog builds an empty WriteLog.

func (*WriteLog) Forget

func (l *WriteLog) Forget(sessionID int64)

Forget drops sessionID's whole write log — Remove's cleanup.

func (*WriteLog) Get

func (l *WriteLog) Get(sessionID int64, path string) (time.Time, bool)

Get returns the last recorded write time for path in sessionID, if any.

func (*WriteLog) Record

func (l *WriteLog) Record(sessionID int64, path string, at time.Time)

Record notes that path was written at at, capping each session at maxWriteLogPaths entries by dropping the single oldest once the cap is exceeded.

Jump to

Keyboard shortcuts

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