Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:0xranx OpenContext Document Lifecycle Management

From Leeroopedia
Knowledge Sources
Domains Knowledge_Management, Content_Management
Last Updated 2026-10-24 12:00 GMT

Overview

A set of principles for creating, organizing, describing, and reorganizing knowledge documents with stable identifiers, ensuring that references survive structural changes over the document's lifetime.

Description

Document lifecycle management addresses the challenge of maintaining a knowledge base where documents are created, moved, renamed, and reorganized over time — all while preserving the ability to reference any document reliably.

The lifecycle consists of:

  • Creation: Documents are registered in a SQLite database with a UUID stable_id, creating both a file on disk and a metadata record.
  • Description: Each document carries a description used for triage and manifest display, keeping descriptions fresh is essential for discoverability.
  • Stable References: The stable_id (UUID) enables `oc://doc/<stable_id>` links that survive renames and moves. The system resolves stable IDs to current paths on demand.
  • Reorganization: Documents and folders can be moved and renamed; the system updates all internal references (paths in the database) atomically.
  • Content Editing: Content is edited directly in markdown files; metadata (description) is managed separately through the store API.

The stable_id system is the key innovation: by assigning a UUID to each document at creation time, references become independent of the document's location in the folder hierarchy. This enables safe reorganization without breaking cross-references.

Usage

Use this principle when building or maintaining a knowledge base where documents need to be referenced from other documents, external tools, or AI agent outputs. The stable_id system should be used for all cross-references to ensure link integrity. Folder and document reorganization should always go through the store API (not direct filesystem manipulation) to keep the database in sync.

Theoretical Basis

The lifecycle model maps document states:

Created→Described→Referenced→[Reorganized]*→Deleted

Stable Reference Resolution:

# Abstract algorithm (NOT real implementation)
def resolve_stable_id(stable_id):
    # SQLite lookup: stable_id -> current rel_path, abs_path
    record = db.query("SELECT * FROM docs WHERE stable_id = ?", stable_id)
    if not record:
        return None  # document deleted or not found
    return {
        "rel_path": record.rel_path,
        "abs_path": record.abs_path,
        "description": record.description,
        "stable_id": record.stable_id,
    }

def move_document(doc_path, dest_folder):
    # 1. Update filesystem: move file
    # 2. Update database: change rel_path, abs_path
    # 3. stable_id remains unchanged
    db.update("docs", set={"rel_path": new_path}, where={"rel_path": doc_path})
    fs.move(old_abs_path, new_abs_path)

The atomic guarantee: stable_id → current path resolution always returns the correct current location, regardless of how many moves or renames have occurred.

Practical Guide

  • Always use the store API: Never create files directly on disk; use `store.createDoc()` to ensure database registration.
  • Keep descriptions fresh: Update descriptions after content changes so manifests remain useful for triage.
  • Use stable links: When referencing documents in other docs or agent outputs, use `oc://doc/<stable_id>` links.
  • Reorganization via API: Move and rename operations through `store.moveDoc()`, `store.renameDoc()`, `store.renameFolder()` update both filesystem and database atomically.

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment