Skip to content

feat(protocol): self-documenting schema and directive grammar#63

Open
c-ferrier wants to merge 1 commit into
Ian-stetsenko:mainfrom
c-ferrier:feat/self-documenting-protocol
Open

feat(protocol): self-documenting schema and directive grammar#63
c-ferrier wants to merge 1 commit into
Ian-stetsenko:mainfrom
c-ferrier:feat/self-documenting-protocol

Conversation

@c-ferrier

@c-ferrier c-ferrier commented May 21, 2026

Copy link
Copy Markdown
Contributor

Transforms Lore from a static convention into a runtime-discoverable knowledge protocol. By formalizing Core and Custom trailer definitions with types, patterns, and operational directives, the CLI now acts as a schema registry for both humans and AI agents.

Key Architectural Shifts:

  1. Discovery Engine: New lore config command exposes the full protocol schema.
  2. Trigger-Action Grammar: Formalized [trigger:parameter] directives for operational rules.
  3. Validation Engine: Custom trailers now separate cardinality (multivalue) from content validation (options, pattern), enabling complex types like multi-value enums.
  4. Flexible Governance: Introduced permissive mode for hybrid schema enforcement.

Usage Examples (.lore/config.toml)

1. Multi-Value Enum (Select many from list)

Allows selecting multiple values from a fixed list.

  [trailers.definitions.Platforms]
  description = "Target operating systems"
  multivalue = true
  validation = "options"
  options = ["Linux", "macOS", "Windows", "Android", "iOS"]

2. Standardizing Attribution (Co-authored-by)

Enforce Git-standard formatting and provide automated squash instructions.

[trailers.definitions.Co-authored-by]
  description = "Git standard co-author attribution"
  multivalue = true
  validation = "pattern"
  pattern = "^.+ <.+@.+>$"
  directives = [
    "[on:squash] Identify all unique intermediate authors in the range",
    "[on:squash] Add authors (excluding the final committer) to this trailer"
  ]

3. Mandatory Unique IDs (Ticket-Id)

[trailers.definitions.Ticket-Id]
  description = "JIRA or Linear ticket identifier"
  multivalue = false
  validation = "pattern"
  pattern = "^PROJ-[0-9]+$"
  required = true

4. Team-Specific Rules

 [trailers.definitions.Department]
  description = "The department responsible for this change"
  multivalue = false
  validation = "options"
  options = ["Engineering", "Product", "Design", "Security"]
  required = true

🔍 Self-Documenting Core Protocol

The native Lore Protocol trailers (Lore-id, Confidence, etc.) now use this same orthogonal model and are discoverable via lore config --core.

Example of what an agent sees for Lore-id:

Lore-id:
    Description: Unique identifier for this knowledge atom
    Type:        string
    Pattern:     ^[0-9a-f]{8}$
    Required:    true
    Directives:
       - [on:amend] Preserve the existing ID to maintain graph integrity
       - [on:commit] Handled by Lore CLI; MUST NOT manually generate IDs or use git hashes
       - [on:commit] The CLI automatically assigns a random 8-character hex string

@c-ferrier c-ferrier requested a review from Ian-stetsenko as a code owner May 21, 2026 18:58
@c-ferrier c-ferrier force-pushed the feat/self-documenting-protocol branch 29 times, most recently from edfa91c to 7d5bbcb Compare May 22, 2026 00:43
@c-ferrier c-ferrier force-pushed the feat/self-documenting-protocol branch 15 times, most recently from da277c0 to 4c65ad2 Compare May 23, 2026 03:45
Re-architected the Lore Protocol from a property-based model to a generic, metadata-driven data engine. This transition unifies built-in and custom trailers into a single logical path where all data structures (LoreTrailers, CommitInput) are unified Record types mapped to readonly string arrays. By anchoring all protocol intelligence—including rebranding, case-normalization, validation, and merging rules—into a central Protocol service, the system achieves perfect structural symmetry while reducing specification changes to a single declarative step.

Key Architectural Components:
- Centralized Protocol Specification: Introduced an absolute Single Source of Truth (SSOT) in core-definitions.ts, enabling full protocol rebranding (e.g., to 'Fred-id') via a single constant change.
- Strictly Hierarchical Import Structure: Established a clean, non-circular information flow from specification to types, constants, and services.
- High-Fidelity Restoration: Faithfully preserved original design patterns (Strategy, Information Expert, Creator) and complex logic precision (multi-hint expiration, confirm-then-loop prompts) while implementing the flat data model.
- Orthogonal Schema Model: Decoupled cardinality from validation rules, allowing for flexible definitions like multi-value enums and dynamic CLI flag registration.

Lore-id: 1d3e207e
Constraint: All trailer data must be stored internally as readonly string[] for structural uniformity
Constraint: The Protocol service must remain the single source of truth for all protocol semantics
Constraint: JSON output must derive structural keys from protocol metadata at the edge
Constraint: Infrastructure constants and domain types must be derived from the core specification
Rejected: Hardcoded property-based model | Rigid and required redundant maintenance for every new trailer
Rejected: Class-based inheritance for trailers | Excessive complexity compared to metadata-driven dynamic Records
Rejected: Loose utility refactoring | Initially clobbered multi-line logic; restored with faithful while-loop precision
Directive: [until:2026-12] Monitor performance of dynamic Record access in large repositories (>10k atoms)
Directive: [on:squash] Carry forward architecturalRationale constraints even when removing intermediate atom IDs
Tested: 460 unit tests passed (expanded from 424 in main branch baseline)
Tested: Verified rebranding capability via 'Fred Test' (Git trailers & JSON synchronization)
Tested: Verified unified requiredness logic and case-insensitive CLI flag mapping
Tested: Manual audit of structural fidelity for all core services against main
Tested: Verified 1-step spec extension workflow via src/util/core-definitions.ts
Confidence: high
Scope-risk: moderate
Reversibility: clean
Assisted-by: Gemini:CLI [lore-protocol]
@c-ferrier c-ferrier force-pushed the feat/self-documenting-protocol branch from b7ff48d to 5d08d53 Compare May 23, 2026 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant