mirror of
https://github.com/profullstack/logicsrc.git
synced 2026-09-10 19:26:00 +00:00
Implements OpenPRD 0001 through Phase 0 (specification, schemas, example, docs surface) and Phase 1 (local engine, CLI, conformance tests). Schemas (17 contracts, JSON Schema Draft 2020-12, additionalProperties:false) manifest, namespace, entity-type, property, relationship-type, constraint, query, action, entity, claim, source, evidence, changeset, review, approval, event, package — registered in @logicsrc/validators and exported from @logicsrc/schemas under https://logicsrc.com/schemas/openontology/. @logicsrc/openontology - canonical JSON + sha256 package digests; YAML, JSON, NDJSON, and inline authoring all compile to the same bytes, so digests are authoring-agnostic - id profile: compact / IRI / urn with one canonicalization rule, prefix bound by a Namespace object so IRIs reverse unambiguously - validation: schema, graph (domain/range, datatypes, dangling refs), provenance (source-or-firstParty, agent runId, derivation inputs), policy (excerpt limits, licensing, visibility, staleness) and declared constraints; four severities, stable codes, text/json/yaml/markdown - portable triple-pattern query AST: multi-hop, 14 operators, asOf and recordedAsOf, per-status filtering, distinct/order/limit, explanation mode, and enforced depth/binding/row limits - append-only store: claims are immutable; dispute/retract/supersede append status transitions and the effective status is the latest one - change sets: 9 operations, atomic pre-flight, conflict detection on stale base revisions, semantic diff with duplicate-identity warnings and affected-query deltas, per-operation reviewer decisions - policy: agents propose but can never apply — the denial keys on actor type, so every scope plus high confidence plus --yolo still cannot apply; merges need approval, bulk retractions need two, undeclared action side effects are denied - JSON-LD 1.1 export/import with PROV-O aliases and lossy-field reporting - pluggable signature envelope with a jws-ed25519 reference profile and a fail-closed trust policy CLI: logicsrc ontology init|validate|lint|build|inspect, entity, claim, query, changeset, import, export, audit. Reads take --format, writes default to a proposal, exit codes are stable for CI. Example: examples/openontology/ethereum-ecosystem — 12 entity types, 17 relationship types, 63 entities, 169 claims, 25 sources, 31 evidence records, 5 saved queries, every claim lifecycle state, and a pending merge proposal. All data is fictional; the directory is removable without affecting any core test. Docs: docs/openontology{,-governance,-interoperability}.md, a real /openontology route, homepage + nav + sitemap entries, and a root README section. Verification: 112 new tests; full monorepo build and every workspace test pass; conformance bundle (18 valid + 13 invalid fixtures) runs against the published schemas alone; Node.js 25 and Bun 1.3 produce byte-identical digests, revisions, event trails, and query results. Not included (later PRD phases): MCP resources, REST/SSE, Turso adapter, TUI and PWA surfaces, RDF/SHACL mappings, source adapters, governed actions. Refs: prd/0001-add-logicsrc-openontology-spec.md Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
207 lines
7 KiB
JSON
207 lines
7 KiB
JSON
{
|
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
"$id": "https://logicsrc.com/schemas/openontology/query.schema.json",
|
|
"title": "LogicSRC OpenOntology Query",
|
|
"description": "The portable triple-pattern query AST, in either ad-hoc form (openontologyQuery) or saved form (kind: SavedQuery with parameters and an expected result shape). Database-specific languages are adapters over this AST, never a substitute for it.",
|
|
"oneOf": [
|
|
{ "$ref": "#/$defs/adHocQuery" },
|
|
{ "$ref": "#/$defs/savedQuery" }
|
|
],
|
|
"$defs": {
|
|
"adHocQuery": {
|
|
"type": "object",
|
|
"required": ["openontologyQuery", "match"],
|
|
"additionalProperties": false,
|
|
"properties": {
|
|
"openontologyQuery": { "type": "string", "pattern": "^\\d+\\.\\d+(\\.\\d+)?$" },
|
|
"ontology": { "type": "string" },
|
|
"match": { "$ref": "#/$defs/match" },
|
|
"where": { "$ref": "#/$defs/where" },
|
|
"select": { "$ref": "#/$defs/select" },
|
|
"include": { "$ref": "#/$defs/include" },
|
|
"orderBy": { "$ref": "#/$defs/orderBy" },
|
|
"distinct": { "type": "boolean", "default": false },
|
|
"asOf": { "type": "string", "format": "date-time" },
|
|
"recordedAsOf": {
|
|
"type": "string",
|
|
"format": "date-time",
|
|
"description": "System-time axis for bitemporal queries."
|
|
},
|
|
"limit": { "type": "integer", "minimum": 1 },
|
|
"offset": { "type": "integer", "minimum": 0 },
|
|
"maxDepth": { "type": "integer", "minimum": 1 },
|
|
"explain": { "type": "boolean", "default": false }
|
|
}
|
|
},
|
|
"savedQuery": {
|
|
"type": "object",
|
|
"required": ["openontology", "kind", "id", "description", "query"],
|
|
"additionalProperties": false,
|
|
"properties": {
|
|
"openontology": { "type": "string", "pattern": "^\\d+\\.\\d+(\\.\\d+)?$" },
|
|
"kind": { "const": "SavedQuery" },
|
|
"id": { "type": "string", "minLength": 1 },
|
|
"label": { "type": "string" },
|
|
"description": { "type": "string", "minLength": 1 },
|
|
"version": { "type": "string" },
|
|
"parameters": {
|
|
"type": "object",
|
|
"additionalProperties": {
|
|
"type": "object",
|
|
"additionalProperties": false,
|
|
"properties": {
|
|
"type": { "type": "string" },
|
|
"required": { "type": "boolean", "default": false },
|
|
"default": {},
|
|
"description": { "type": "string" }
|
|
}
|
|
}
|
|
},
|
|
"expects": {
|
|
"type": "object",
|
|
"additionalProperties": false,
|
|
"description": "Expected result shape, used by tests and UI.",
|
|
"properties": {
|
|
"columns": { "type": "array", "items": { "type": "string" } },
|
|
"minRows": { "type": "integer", "minimum": 0 },
|
|
"maxRows": { "type": "integer", "minimum": 0 }
|
|
}
|
|
},
|
|
"query": { "$ref": "#/$defs/queryBody" },
|
|
"extensions": { "type": "object" }
|
|
}
|
|
},
|
|
"queryBody": {
|
|
"type": "object",
|
|
"required": ["match"],
|
|
"additionalProperties": false,
|
|
"properties": {
|
|
"match": { "$ref": "#/$defs/match" },
|
|
"where": { "$ref": "#/$defs/where" },
|
|
"select": { "$ref": "#/$defs/select" },
|
|
"include": { "$ref": "#/$defs/include" },
|
|
"orderBy": { "$ref": "#/$defs/orderBy" },
|
|
"distinct": { "type": "boolean", "default": false },
|
|
"asOf": { "type": "string" },
|
|
"recordedAsOf": { "type": "string" },
|
|
"limit": { "type": "integer", "minimum": 1 },
|
|
"offset": { "type": "integer", "minimum": 0 },
|
|
"maxDepth": { "type": "integer", "minimum": 1 }
|
|
}
|
|
},
|
|
"match": {
|
|
"type": "array",
|
|
"minItems": 1,
|
|
"items": {
|
|
"type": "object",
|
|
"required": ["subject", "predicate", "object"],
|
|
"additionalProperties": false,
|
|
"description": "A triple pattern. Terms starting with '?' are variables; everything else is a constant.",
|
|
"properties": {
|
|
"subject": { "type": "string", "minLength": 1 },
|
|
"predicate": { "type": "string", "minLength": 1 },
|
|
"object": {
|
|
"anyOf": [
|
|
{ "type": "string", "minLength": 1 },
|
|
{
|
|
"type": "object",
|
|
"additionalProperties": false,
|
|
"properties": {
|
|
"entity": { "type": "string" },
|
|
"value": {},
|
|
"variable": { "type": "string" }
|
|
}
|
|
}
|
|
]
|
|
},
|
|
"optional": { "type": "boolean", "default": false },
|
|
"bindClaim": {
|
|
"type": "string",
|
|
"description": "Variable bound to the matched claim id, for explanations."
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"where": {
|
|
"type": "array",
|
|
"items": {
|
|
"type": "object",
|
|
"required": ["variable", "operator"],
|
|
"additionalProperties": false,
|
|
"properties": {
|
|
"variable": { "type": "string", "minLength": 1 },
|
|
"field": {
|
|
"type": "string",
|
|
"description": "Entity field or property predicate to compare. Defaults to the bound term itself."
|
|
},
|
|
"operator": {
|
|
"type": "string",
|
|
"enum": [
|
|
"eq",
|
|
"neq",
|
|
"lt",
|
|
"lte",
|
|
"gt",
|
|
"gte",
|
|
"in",
|
|
"not-in",
|
|
"exists",
|
|
"not-exists",
|
|
"contains",
|
|
"starts-with",
|
|
"matches",
|
|
"before",
|
|
"after"
|
|
]
|
|
},
|
|
"value": {}
|
|
}
|
|
}
|
|
},
|
|
"select": {
|
|
"type": "array",
|
|
"minItems": 1,
|
|
"items": { "type": "string", "minLength": 1 }
|
|
},
|
|
"include": {
|
|
"type": "object",
|
|
"additionalProperties": false,
|
|
"description": "Claim-status inclusion policy. Each status is filterable independently.",
|
|
"properties": {
|
|
"claimStatus": {
|
|
"type": "array",
|
|
"items": {
|
|
"type": "string",
|
|
"enum": ["asserted", "proposed", "disputed", "retracted", "superseded", "derived"]
|
|
},
|
|
"uniqueItems": true
|
|
},
|
|
"derived": { "type": "boolean" },
|
|
"labels": { "type": "boolean", "description": "Expand entity labels in results." },
|
|
"properties": {
|
|
"type": "array",
|
|
"items": { "type": "string" },
|
|
"description": "Additional entity properties to expand in results."
|
|
},
|
|
"visibility": {
|
|
"type": "array",
|
|
"items": { "type": "string", "enum": ["public", "internal", "private"] },
|
|
"uniqueItems": true
|
|
}
|
|
}
|
|
},
|
|
"orderBy": {
|
|
"type": "array",
|
|
"items": {
|
|
"type": "object",
|
|
"required": ["variable"],
|
|
"additionalProperties": false,
|
|
"properties": {
|
|
"variable": { "type": "string" },
|
|
"field": { "type": "string" },
|
|
"direction": { "type": "string", "enum": ["asc", "desc"], "default": "asc" }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|