kb

package
v0.8.1 Latest Latest
Warning

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

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

Documentation

Overview

Package kb is shared infrastructure for ox's knowledge-base git repos: the per-project ledger and team-context clones. They have the same shape — a managed git working tree the daemon pulls and the CLI pushes to — and the same multi-writer hazards: server-side seed, CLI-side seed, several coworkers committing in parallel.

Anything that's true for both repo types belongs here. Things that are only true for one of them stay in their own package (internal/ledger/* for ledger-specific paths and lifecycle; the team-context layer in cmd/ox + internal/teamdocs for TC-specific behavior).

Index

Constants

This section is empty.

Variables

View Source
var MergeUnionPaths = []string{
	"AGENTS.md",
	"CLAUDE.md",
	"README.md",
	"CONVENTIONS.md",
	"SOUL.md",
	".gitignore",
}

MergeUnionPaths lists the root metadata files where multiple writers (server-side seed, CLI seed, coworker edits, doctor) routinely touch the same file concurrently in BOTH ledger and team-context repos. Declaring merge=union for these tells git to concatenate both sides on conflict instead of halting the rebase, which turns "wedged repo after first push" into "repo keeps moving; duplicate lines can be deduped later by a doctor pass."

merge=union is the same driver git uses for changelogs and NEWS files. It is safe for append-mostly metadata. It is NOT applied to session, history, murmur, or memory entry paths — those are conflict-free by construction since each entry has a unique timestamp- or id-based path.

Files included:

  • AGENTS.md, CLAUDE.md, README.md, CONVENTIONS.md — appear at the root of both repo types; touched by humans, AI coworkers, server seed, ox prime injection.
  • SOUL.md — team-context "soul" doc; multi-coworker writes are the point of the file.
  • .gitignore — both repo types may have ignore patterns added by either side.

Exported so external tooling and tests can introspect the canonical list without re-deriving it.

Functions

func EnsureMergeAttributes

func EnsureMergeAttributes(repoPath string) (changed bool, err error)

EnsureMergeAttributes writes or updates the ox-managed merge-driver block in the KB repo's per-clone attributes file (.git/info/attributes). Idempotent. Preserves any content outside the managed block. Returns true if the file changed, false if it was already up to date.

The repo must already be a git working tree (have a .git directory). Caller passes the working-tree root, not the .git directory.

Designed to be safe to call on every pull/push cycle: idempotent, atomic write (temp + rename), best-effort error handling.

Types

type Bubble added in v0.8.0

type Bubble struct {
	// KBID is the immutable kb identifier from /api/v1/kb. Empty for
	// legacy rows that haven't been migrated into the kb table yet.
	KBID string

	// Type is the kb_type bucket. Legacy team rows synthesize KBTypeTeam;
	// legacy ledger rows synthesize KBTypeRepo. Unknown server values are
	// already collapsed to KBTypeUnknown by the kb client.
	Type api.KBType

	// Slug is the human-readable slug (kebab-case). Used as the secondary
	// dedup key together with Endpoint when neither KBID nor RepoID matches.
	Slug string

	// Name is the display name.
	Name string

	// ViewerRole is the caller's role on this bubble ("owner", "member",
	// "viewer"). Only kb-API rows populate this today.
	ViewerRole string

	// LocalPath is the on-disk checkout path. For kb-API rows this is the
	// canonical KBDir(kb_id); for legacy rows it's whatever path the
	// synthesizer reports (team context dir or ledger dir).
	LocalPath string

	// RepoURL is the git clone URL when known.
	RepoURL string

	// RepoID is the SageOx repo_id, populated for legacy ledger rows and
	// for kb-API rows when the server supplies it. Used as the secondary
	// dedup key.
	RepoID string

	// Endpoint is the SageOx API endpoint this row belongs to (normalized
	// via endpoint.NormalizeEndpoint). Used together with Slug as the
	// tertiary dedup key.
	Endpoint string

	// Source identifies which fan-out branch produced this row.
	Source Source

	// Legacy is true for synthesized rows from /api/v1/cli/repos and the
	// local ledger registry. kb-API rows have Legacy=false.
	Legacy bool
}

Bubble is the unified row returned by Merge. It's a superset of the fields produced by the three sources — empty values are normal for any field that the source row didn't supply.

type KBSource added in v0.8.0

type KBSource interface {
	ListBubbles(ctx context.Context) ([]api.KB, error)
}

KBSource is the contract for fetching new-API kb rows. Defined as an interface so tests can supply fakes without spinning up an httptest server when they only care about the merge logic.

type LedgerSource added in v0.8.0

type LedgerSource interface {
	ListLedgers(ctx context.Context) ([]LegacyLedgerRow, error)
}

LedgerSource is the contract for enumerating local ledger registry entries. Implementations typically scan paths.LedgersDataDir(...) for each known endpoint and read each ledger's project config.

type LegacyLedgerRow added in v0.8.0

type LegacyLedgerRow struct {
	RepoID   string // SageOx repo_id (extracted from path or project config)
	Name     string // display name (typically the host repo's name)
	Slug     string // optional kebab-case slug
	LocalDir string // on-disk ledger checkout path
	Endpoint string // SageOx API endpoint this ledger is bound to
	URL      string // git clone URL when known (rare for legacy ledgers)
}

LegacyLedgerRow is the merger-facing projection of a local ledger.

type LegacyTeamRow added in v0.8.0

type LegacyTeamRow struct {
	TeamID   string // team_xxx — used as RepoID-equivalent for dedup
	Name     string
	Slug     string
	URL      string // git clone URL
	LocalDir string // on-disk team-context checkout (may be empty if not yet cloned)
}

LegacyTeamRow is the merger-facing projection of a /api/v1/cli/repos team-context entry. Decoupled from api.RepoInfo so a future API shape change doesn't ripple into the merger.

type LegacyTeamSource added in v0.8.0

type LegacyTeamSource interface {
	ListTeamContexts(ctx context.Context) (rows []LegacyTeamRow, endpoint string, err error)
}

LegacyTeamSource is the contract for fetching legacy team-context rows from /api/v1/cli/repos. The merger only needs the repo map and the endpoint the rows came from — the rest of ReposResponse is unused.

type MergeResult added in v0.8.0

type MergeResult struct {
	Bubbles  []Bubble
	Warnings []SourceWarning
}

MergeResult is the return value of Merge. Bubbles is the deduped union; Warnings is one entry per source that errored (non-fatally).

type Merger added in v0.8.0

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

Merger fans out to the three sources and merges the results. Construct via NewMerger; the zero value is not usable.

func NewMerger added in v0.8.0

func NewMerger(kb KBSource, teams LegacyTeamSource, ledger LedgerSource) *Merger

NewMerger constructs a Merger. Any of the three sources may be nil — a nil source contributes zero rows and never produces a warning, which is the expected shape during daemon startup or in narrow tests that only exercise one branch.

func (*Merger) Merge added in v0.8.0

func (m *Merger) Merge(ctx context.Context) (MergeResult, error)

Merge fans out in parallel to all three sources, deduplicates by stable identifier, and returns the unified result. The returned error is reserved for catastrophic failures unrelated to any single source — today it's always nil; per-source failures land in Warnings.

type Source added in v0.8.0

type Source string

Source identifies which of the three fan-out sources produced a Bubble or a warning. Stable strings — surfaced in JSON output and logs.

const (
	SourceKB         Source = "kb"
	SourceTeamLegacy Source = "team_legacy"
	SourceLedger     Source = "ledger_legacy"
)

type SourceWarning added in v0.8.0

type SourceWarning struct {
	Source Source
	Err    string
}

SourceWarning is a non-fatal error from one of the three sources. The merger collects these into MergeResult.Warnings so the caller can render them without losing the rows from sources that did succeed.

Jump to

Keyboard shortcuts

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