omp packages

pi-okf-god0.1.3

Pi extension: an OKF v0.3 knowledge catalog with a typed knowledge graph, an emergent ontology, predicate traversal, a scaffold/check gate for documentation, exports and an ArcadeDB projection.

nicolas_santa Published 4 days ago MIT ~0 downloads/mo

Untested on omp

This is a pi package. No one has reported whether it works on omp yet. If you try it, add your result below.

Did it work for you?

Result

One report per person. A new report replaces your old one.

Reports 0

No reports yet.

Readme

okf-god

A pi extension that indexes skills, docs, and agents written in the Open Knowledge Format v0.3 (OKF, GoogleCloudPlatform/knowledge-catalog), loads them on demand (requirement-based lazy loading), lets the model navigate the bundle link graph, tracks which resources the agent actually used, and displays that usage in the TUI.

  • Frontmatter-only indexing at scan time; bodies are read strictly on demand.
  • Graph navigation (OKF §6): markdown links between concepts are directed edges; the model can walk outgoing links and backlinks, and you can render the bundle as bounded Mermaid.
  • Knowledge graph and ontology: edges carry predicates from every carrier (PGM link titles, token: titles, HTML rel, relations: lists, OKF path fields); okf_schema maps the types, predicates, hubs and sections; okf_query traverses by predicate, finds chains, measures impact.
  • Declared vocabulary, diagnostics, export: type: Edge Type / type: Class schema concepts and x-okf-god-* keys in the root index.md extend the vocabulary; /okf-types --check reports undeclared predicates and direction violations as advice; /okf-export writes JSON, Mermaid, JSON-LD, N-Triples or an ArcadeDB SQL script; /okf-sync projects the graph into ArcadeDB.
  • OKF v0.3 trust & lifecycle surfaced: type, resource, status, stale_after, generated.at, and derived trust tiers (unverified / machine-confirmed / human-reviewed).
  • Permissive conformance (OKF §11): unknown fields, unknown types, missing frontmatter, and broken links are tolerated — never rejected.

Install

The npm package is pi-okf-god (pi packages take the pi- prefix); the extension is okf-god.

# from npm (recommended)
pi install npm:pi-okf-god

# or the one-liner from GitHub: pi clones the repo, installs runtime deps, registers the extension
pi install https://github.com/nsanta/okf-god

# for development: clone and load in place (your dependency tree, your edits)
git clone https://github.com/nsanta/okf-god
cd okf-god && npm install
pi install ./okf-god        # or: pi install /absolute/path/to/okf-god

@earendil-works/pi-tui, typebox, and the other @earendil-works/* packages are supplied by the pi host (declared as peer dependencies) — only yaml is vendored. For development, load a single file directly with pi --extension ./src/index.ts.

The default-export factory (src/index.ts) receives ExtensionAPI; the factory body does no filesystem work — the catalog and link graph build lazily on first use or on session_start.

What gets indexed

Kind Default roots Names from
skill <cwd>/.pi/skills, <cwd>/.agents/skills, ~/.pi/agent/skills, ~/.agents/skills frontmatter name, else directory
doc <cwd>/docs filename slug
agent <cwd>/.pi/agents, ~/.pi/agent/agents, ~/.agents frontmatter name, else filename

Skipped everywhere: node_modules/, 99-archive/, hidden directories, and the reserved OKF filenames index.md / log.md / index.html / log.html (§3.1).

OKF-HTML v0.1: .html documents are indexed alongside .md in every root per the OKF-HTML v0.1 profile — <title> plus okf: metas supply the metadata, doc slugs are the filename minus extension, an .md/.html slug collision keeps both entries (name-based lookup prefers the .html one; exact paths are unambiguous), and skills stay Markdown (SKILL.md). Markdown is the canonical OKF format; OKF-HTML is a per-document exception and an export target, not the default for new documents.

Override roots per project or user with .pi/okf.json (cwd) or ~/.pi/agent/okf.json:

{
  "skills": ["knowledge/skills"],
  "docs": ["docs"],
  "agents": ["~/my-agents"],
  "exclude": ["drafts"]
}

Relative paths resolve against cwd; ~ is expanded; missing roots are skipped silently.

Model tools

Tool Parameters What it does
okf_search query, kind?, current? Weighted ranking (tags ×3, name ×2.5, title ×2, description/section ×1), top 8, with trust/status.
okf_read path, maxChars? (default 20000) Resolves entry by exact path or unique name; returns content + OKF summary (type/status/trust/stale/sources) + Links: section; records usage.
okf_links path?/name?, direction?, type? (predicate or link), max? (10) Graph navigation: every edge with its predicate (path fields); broken and not a concept targets marked.
okf_list kind? Compact table: name / kind / description (80 chars) / status.
okf_schema type?, diagnostics? The map before searching: concept types with counts, predicates with carriers and observed from → to types, hubs, orphans, section tree.
okf_query from?, via?, direction?, depth?, current?, types?, max?, to?, impact? Traversal without reading bodies: a predicate-filtered neighborhood, the shortest chains between two concepts, what points at a concept, or the directory tree around it.
okf_scaffold (deferred) title, type?, section?, root?, name?, format?, description?, tags?, links?, actor?, write? Proposes a new concept from the live bundle (path, slug, type like its neighbours; Markdown, or OKF-HTML on request) and renders its skeleton with honest provenance (status: draft, generated.by/at, no verified). Writes only on request, never overwrites; the body stays yours.
okf_check (deferred) path The gate before a draft enters the bundle: required type, provenance, lifecycle values, links, predicates, name shadowing. Advisory; nothing is modified.

Deferred tools. okf_scaffold and okf_check are for writing documentation, so they are not declared in every prompt; the six other tools cost about 1,060 tokens per request. Activate them with pi --tools +okf_scaffold,+okf_check, or once in settings ("defaultTools": ["+okf_scaffold", "+okf_check"]); when the built-in tool_search is active the model can find them too. /okf-check always works.

okf_read truncates long files and appends an explicit marker naming the file path so the model can read the rest itself.

Lifecycle (OKF v0.3): okf_read names the replacement of a deprecated concept (Replaced by:), marks a status outside stable/draft as (not current), and treats a stale_after it cannot parse as not fresh (malformed). okf_search with current: true leaves deprecated and unknown statuses out.

Commands

Command Effect
/okf-list [kind] Catalog table in the UI (kind completion provided).
/okf-links <name> Graph neighbors for one entry, same resolution as the tool.
/okf-types [name] The schema: types, predicates, hubs, orphans, sections; one type or predicate in detail; --check adds diagnostics.
/okf-export [format] [file] Write the graph as json, mermaid, jsonld, ntriples or an ArcadeDB SQL script (default ./okf-graph.json).
/okf-sync Project the graph into the ArcadeDB server configured in .pi/okf.json (graph.backend).
/okf-check <file> Check a draft and print its findings (same as the tool).
/okf-graph Bounded Mermaid flowchart LR of the bundle graph (degree-ranked; --mermaid labels typed edges).
/okf-usage Per-kind distinct-usage counts for this session.
/okf-reload Invalidate catalog + graph caches and rescan.

Knowledge graph and ontology

Every way a bundle can assert a relation is read into one edge model, each edge tagged with its carrier and, when it has one, its predicate:

Carrier Example Predicate comes from
OKF path field (§6.4) superseded_by: /metrics/gross-margin.md the field (superseded_by, source, resource, …)
PGM link title [raw](/tables/raw.md "{type: depends_on, since: 2024}") the type of a YAML flow mapping; the mapping becomes edge properties
token: link title [customers](/tables/customers.md "joins-with: on customer_id") the token, only when it is a known predicate
HTML rel <a href="/tables/raw.html" rel="depends_on"> the first known predicate among the tokens
relations: list relations: [{type: supported_by, target: /policies/margin.md, evidence: margin-policy}] type / predicate / rel of each entry; the entry becomes properties
plain link [notes](./notes.md) none: an untyped edge, never related_to by default

Predicates are normalized through a small vocabulary (src/vocabulary.ts): dependsOn, depends-on and depends_on are one predicate; aliases map onto a canonical name; inverses are declared, never authored (supersedes is the inverse of superseded_by, so okf_query with via: superseded_by, direction: in finds what a concept replaces). Unknown predicates keep their spelling. OKF v0.3 defers typed relationships (§12.2); this is the experiment it asks for, and the rationale is in the knowledge-graph research note.

  • okf_schema is the map before searching: concept types with counts, predicates with their carriers and observed from → to types, hubs, orphans, and the section tree (the only hierarchy OKF defines). Nothing in it is authored; it is discovered from the graph on every build.
  • okf_query traverses without reading bodies: a predicate-filtered neighborhood (from + via, 1–3 hops), the shortest chains between two concepts (from + to), what points at a concept (impact), or the directory tree around it (via: "tree"). Deprecated concepts are traversed through but left out of the results unless current: false.
  • /okf-graph --mermaid labels typed edges (A -- depends_on --> B); /okf-types prints the schema.

Declared vocabulary

The emergent ontology needs no authoring. A bundle can go further and declare its vocabulary with ordinary concepts, read by okf_schema, okf_query and the graph:

---
type: Edge Type
title: Feeds into
description: Output of this concept flows into the target.
from: [Service, Job]
to: [Table, Topic]
inverse_of: fed_by
uri: ex:feedsInto
---
  • type: Edge Type declares a predicate: named by predicate, else by its file slug; from/to list the OKF types it may connect; symmetric, inverse_of, uri (IRI or CURIE) are optional.
  • type: Class declares a concept class (named by class, else title).
  • The root index.md grounds them: x-okf-god-prefixes: { ex: "https://example.org/ontology#" } and x-okf-god-base: "https://acme.example/knowledge/" (extension keys, OKF v0.3 §4.1).
  • Declared predicates are "known": they unlock token: link titles, HTML rel tokens and flat frontmatter keys (feeds_into: [/tables/events.md]) as edge carriers.
  • /okf-types --check and okf_schema with diagnostics: true compare what the bundle asserts with what it declares: predicates in use that nothing declares, edges that leave or arrive at a type a declared from/to excludes, duplicate declarations, inverses that do not exist. All of it is advice; nothing is ever removed.

Export and the ArcadeDB projection

/okf-export [json|mermaid|jsonld|ntriples|arcadedb] [file] writes the graph: a JSON document (nodes, every edge occurrence, bundles, ontology), typed Mermaid, JSON-LD with an inline context (@vocab okf, the bundle base, CURIE prefixes, every predicate grounded to its IRI), RDF N-Triples, or an ArcadeDB SQL script that rebuilds the projection from scratch.

/okf-sync projects the graph into an ArcadeDB server (opt in with .pi/okf.json):

{ "graph": { "backend": "arcadedb", "url": "http://localhost:2480", "database": "okf" } }

The API token or password come from the environment only (OKF_ARCADEDB_TOKEN, OKF_ARCADEDB_PASSWORD). The projection is replaced on every sync so it converges to the files; nothing flows back into the bundle. Inside ArcadeDB the OKF type of a concept is its vertex type (Reference EXTENDS Concept), each predicate is an edge type, and Cypher answers what the bundle only implied: MATCH (a:Concept {id: 'ingestion'})-[:depends_on*2]->(c) RETURN c. scripts/arcadedb-smoke.ts runs the whole round trip against a live server. From a git checkout: node --experimental-strip-types scripts/arcadedb-smoke.ts; from an installed package (Node refuses to strip types under node_modules), use the TypeScript loader pi ships: ~/.pi/agent/npm/node_modules/.bin/tsx ~/.pi/agent/npm/node_modules/pi-okf-god/scripts/arcadedb-smoke.ts. Set ARCADEDB_URL, ARCADEDB_USER and ARCADEDB_PASSWORD and pass the workspace directory to project.

Contract and gate: scaffold and check

okf-god does not write documentation; it owns the contract around it. okf_scaffold proposes where a new concept goes and what its frontmatter must say, taken from the live bundle (section tree, slug, the neighbours' type), renders Markdown by default (OKF-HTML on request as a per-document exception), and records provenance honestly: status: draft, generated: { by: pi/<model>, at }, and never a verified entry. The body is a placeholder for the author, with links to concepts that exist. okf_check (/okf-check <file>) reads a draft the way okf-god will read it once cataloged and reports what a consumer would trip over: a missing type, generated.at without generated.by, a generator that verifies its own content, an unknown status, a malformed stale_after, a superseded_by that does not resolve, links that break, predicates nothing declares, a name another concept would shadow. Nothing is modified and nothing is rejected. Why okf-god stops at the gate instead of generating documentation: doc-generation assessment.

Usage display & persistence

A belowEditor widget shows live counts, e.g. OKF ▸ 2 skills · 1 doc · 1 agent (this session), hidden when zero. Every usage event is appended to the session as a custom entry (okf-god:usage) and reconstructed on session_start from ctx.sessionManager.getBranch().

Usage sources: okf_read (tool), skill_read / agent_read (native read-shaped tool calls whose path matches a cataloged SKILL.md / agent file), and agent_spawn (subagent-style tool calls naming a cataloged agent). Detection is defensive: unknown event shapes never throw.

OKF v0.3 alignment

okf-god reads OKF v0.3 and keeps v0.2 bundles working through the §12.1 fallbacks.

Spec Where in okf-god
§4.1 frontmatter fields CatalogEntry.okfType/resource/staleAfter/generatedAt/supersededBy/trustTier
§5.2–5.3 trust tiers src/trust.ts: deriveTrustTier counts only verifications at or after generated.at; every verified entry needs by and at; team: is non-human
§5.4 status & superseded_by src/trust.ts (isCurrent: stable and draft only), src/policy.ts (replacementFor); okf_read prints Replaced by: and marks other statuses (not current)
§5.5 staleness stalenessState: none, fresh, stale, or malformed (a present value that does not parse is never fresh)
§6 links and paths src/graph.ts: inline, full/collapsed/shortcut reference links to .md and .html concepts, <angle> destinations, percent-decoding; fenced code, inline code and images hold no links
§6.2, §6.4 path fields superseded_by, resource, computation, executor.resource, attester.resource, sources[].resource become edges when they resolve; v0.2 bundles may fall back to the bundle root
§3.1 reserved filenames index.md / log.md / index.html / log.html skipped at scan; a root index.md frontmatter is read as bundle metadata (§8.1)
§8.1 bundle metadata src/bundle.ts: okf_version, title, description, license and extension keys of each scan root's index.md (or OKF-HTML index.html)
OKF-HTML v0.1 profile src/htmlmeta.ts (never-throw parser); .html scanning in src/catalog.ts (incl. headings); anchor-link graph + format-agnostic /name resolution in src/graph.ts; readable-text okf_read in src/reader.ts; heading search terms in src/search.ts (docs/okf-html.html)
§11 permissive conformance no document is ever rejected; unknown keys/types ignored; a scalar list value is one item

One deliberate deviation: a .md file without type is still indexed as a generic concept. OKF §3.2 lets a consumer skip such files, but pi skills and agents never carry type, so okf-god keeps them and shows type: unknown.

sources (§5.1) are not retained in the catalog (size); okf_read summarizes their count.

Development

npm test          # vitest — 313 tests, 32 files
npm run typecheck # tsc --noEmit (strict)

Pure modules (frontmatter, trust, catalog, roots, search, reader, graph, usage) are fully unit-tested with mkdtemp fixture trees; src/index.ts wiring is covered by mock-based tests. See docs/architecture.md for the design, diagrams, and decisions.

No commits are made by agents; delivery is an ordinary repository decision.

Benchmark

bench/ measures token consumption and exact-match retrieval accuracy of okf-god vs standard pi: same model, same synthetic OKF fixture, byte-identical prompts, alternating arm order.

Suites: fact-qa and multi-hop run by default. Three opt-in suites (--tasks) measure the knowledge graph: typed-multihop (the only route is a chain of depends_on edges; an untyped link leads to a decoy), in-force (a retired value beside its current one), and negative-control (a question the documentation does not answer; gold is the literal not stated). They live in a second bundle root, typed/, that the workspace .pi/okf.json adds beside docs/.

node --experimental-strip-types bench/run.ts        # print the plan; no model calls, exits 0
node --experimental-strip-types bench/run.ts --yes  # live run — spends real API tokens
npx vitest run --config bench/vitest.config.ts      # bench unit tests (no pi spawned)

With --yes, results land in bench/results/<timestamp>/: raw.csv + raw.jsonl per-run records, summary.md (per arm × suite stats, two-arm deltas, honesty notes), plan.json, and the fixture kept under workspace/. Module map and verified pi --mode json contract: bench/README.md.