Add the LogicSRC OpenContext specification

OpenContext is an open specification for durable, portable, permissioned,
provenance-aware context shared between humans and AI agents. It defines how
organizational knowledge is described, authorized, versioned, resolved,
audited, and handed between replaceable workers without losing institutional
state.

Follows the OpenPRD/OpenOntology pattern already in the repo: self-contained
JSON Schemas in @logicsrc/schemas, a reference implementation package, CLI
subcommands, docs, examples, and an OpenPRD record.

Schemas (8, all self-contained so a third party can fetch one file and
validate against it with no further resolution):
  manifest, object, bundle, role, provenance, decision, diagnostic,
  audit-event — registered in @logicsrc/validators and schemas:validate.

Reference implementation (@logicsrc/opencontext):
  loader with upward manifest discovery, the full resolution pipeline,
  authority/supersession, permissions, redaction, lifecycle, provenance,
  deterministic digests, doctor, search, graph, history/diff, guarded writes,
  audit events, and file/http/git/sqlite adapters.

CLI: all 15 specified commands, as a standalone `opencontext` binary and as
`logicsrc context`, sharing one implementation so the two cannot drift.

Design decisions worth noting:

- Supersession is declared, never inferred from version numbers. Inferring it
  would hide the governance failure it represents and make
  multiple-active-versions and duplicate-canonical impossible to detect.

- The bundle digest identifies the resolved context, not the moment it was
  computed, so generated_at/bundle_id/digest/as_of are excluded while objects,
  lifecycle states, exclusions and warnings are covered. That is what lets a
  decision record cite exactly the context that produced it.

- A role's own max_classification beats an inherited one, so a ceiling on a
  shared base role cannot silently cap a role deliberately granted more;
  requesting several roles at once still takes the lowest, so combining roles
  never escalates.

- Scope wildcards match whole dotted segments only. A trailing .* covers a
  subtree; an interior * matches exactly one segment. Substring matching here
  would be an access-control bug.

- --include narrows an existing scope and is applied after it, never merged
  into it, so a request can never widen what a role holds.

Verified: 226 tests across core primitives, permissions/redaction, the
resolution pipeline, security, the published conformance fixtures (13 valid,
35 invalid, 8 resolution scenarios), project behaviour, and the five shipped
examples — which are held to --strict and a 100% health score. Benchmarks meet
every published budget (resolve 1,000 objects in ~33ms against a 2s target).

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Anthony Ettinger 2026-08-09 18:22:42 +00:00
parent 1bb7ba6e60
commit ec3ed64f20
211 changed files with 17234 additions and 6 deletions

View file

@ -0,0 +1,10 @@
---
id: policies.refunds-observed
type: policy
layer: L3
authority: observed
owner: support
canonical_source: true
---
An agent observed staff granting refunds up to 60 days.

View file

@ -0,0 +1,12 @@
---
id: policies.refunds
type: policy
layer: L3
authority: canonical
owner: support
canonical_source: true
conflicts_with:
- policies.refunds-observed
---
Refunds within 30 days.

View file

@ -0,0 +1,21 @@
{
"description": "A declared conflict that authority settles is still reported, never silently hidden. Canonical outranks observed, and the losing side is named in the warning.",
"resolve": {
"role": "everyone",
"at": "2026-08-09T12:00:00Z"
},
"expect": {
"included": [
"policies.refunds",
"policies.refunds-observed"
],
"warnings": [
"conflict-declared"
]
},
"validate": {
"expectDiagnostics": [
"conflict-declared"
]
}
}

View file

@ -0,0 +1,11 @@
opencontext: "1.0"
id: conflict-test
name: Declared conflicts
collections:
policies: ./context/policies/**
roles:
everyone:
include:
- policies.*

View file

@ -0,0 +1,11 @@
---
id: docs.handbook
type: knowledge
layer: L2
authority: approved
owner: ops
classification: internal
canonical_source: true
---
How we work.

View file

@ -0,0 +1,11 @@
---
id: docs.litigation
type: knowledge
layer: L2
authority: approved
owner: legal
classification: restricted
canonical_source: true
---
Privileged and confidential.

View file

@ -0,0 +1,32 @@
{
"description": "Classification bounds a role regardless of scope: support includes docs.* and is still denied the restricted document, while legal is not.",
"resolve": {
"role": "support",
"at": "2026-08-09T12:00:00Z"
},
"expect": {
"included": [
"docs.handbook"
],
"excluded": [
{
"id": "docs.litigation",
"reason": "classification-denied"
}
]
},
"also": [
{
"resolve": {
"role": "legal",
"at": "2026-08-09T12:00:00Z"
},
"expect": {
"included": [
"docs.handbook",
"docs.litigation"
]
}
}
]
}

View file

@ -0,0 +1,16 @@
opencontext: "1.0"
id: classification-test
name: Classification ceiling
collections:
docs: ./context/docs/**
roles:
support:
include:
- docs.*
max_classification: internal
legal:
include:
- docs.*
max_classification: restricted

View file

@ -0,0 +1,10 @@
---
id: mission
type: mission
layer: L0
authority: canonical
owner: founders
canonical_source: true
---
Make refunds boring.

View file

@ -0,0 +1,10 @@
---
id: policies.internal.margins
type: policy
layer: L3
authority: canonical
owner: finance
canonical_source: true
---
Gross margin floor is 62%.

View file

@ -0,0 +1,10 @@
---
id: policies.refunds
type: policy
layer: L3
authority: canonical
owner: support
canonical_source: true
---
Refunds within 30 days.

View file

@ -0,0 +1,19 @@
{
"description": "An exclude pattern beats an include that also matches. Deny overrides allow, unconditionally.",
"resolve": {
"role": "support",
"at": "2026-08-09T12:00:00Z"
},
"expect": {
"included": [
"mission",
"policies.refunds"
],
"excluded": [
{
"id": "policies.internal.margins",
"reason": "scope-exclusion"
}
]
}
}

View file

@ -0,0 +1,17 @@
opencontext: "1.0"
id: scope-test
name: Deny overrides allow
context:
mission: ./context/mission.md
collections:
policies: ./context/policies/**
roles:
support:
include:
- mission
- policies.*
exclude:
- policies.internal.*

View file

@ -0,0 +1,12 @@
---
id: policies.refunds
type: policy
layer: L3
version: 2
authority: canonical
owner: support
canonical_source: true
updated: 2026-08-01T00:00:00Z
---
Refunds within 60 days. Nobody added supersedes.

View file

@ -0,0 +1,12 @@
---
id: policies.refunds
type: policy
layer: L3
version: 1
authority: canonical
owner: support
canonical_source: true
updated: 2026-01-01T00:00:00Z
---
Refunds within 30 days.

View file

@ -0,0 +1,10 @@
{
"description": "Two active canonical objects for one id, with no supersession linking them. Canonical means exactly one source of truth, so this is an error a strict run must fail on.",
"validate": {
"expectDiagnostics": [
"duplicate-canonical",
"multiple-active-versions"
],
"expectFailure": true
}
}

View file

@ -0,0 +1,11 @@
opencontext: "1.0"
id: duplicate-test
name: Duplicate canonical
collections:
policies: ./context/policies/**
roles:
everyone:
include:
- policies.*

View file

@ -0,0 +1,11 @@
---
id: notes.current
type: note
layer: L2
authority: reference
owner: ops
canonical_source: true
updated: 2026-08-01T00:00:00Z
---
Fresh, inside the 30d window.

View file

@ -0,0 +1,12 @@
---
id: notes.expired
type: note
layer: L2
authority: reference
owner: ops
canonical_source: true
updated: 2026-08-01T00:00:00Z
expires: 2026-08-05T00:00:00Z
---
Expired before the resolution timestamp.

View file

@ -0,0 +1,12 @@
---
id: notes.future
type: note
layer: L2
authority: reference
owner: ops
canonical_source: true
updated: 2026-08-01T00:00:00Z
valid_from: 2027-01-01T00:00:00Z
---
Not valid until next year.

View file

@ -0,0 +1,11 @@
---
id: notes.stale
type: note
layer: L2
authority: reference
owner: ops
canonical_source: true
updated: 2026-01-01T00:00:00Z
---
Outside the 30d window, so stale — resolved anyway, and reported.

View file

@ -0,0 +1,30 @@
{
"description": "Lifecycle is computed against the resolution timestamp. Expired and not-yet-valid context is excluded; stale context is still resolved, and warned about \u2014 silence would be worse than staleness.",
"resolve": {
"role": "everyone",
"at": "2026-08-09T12:00:00Z"
},
"expect": {
"included": [
"notes.current",
"notes.stale"
],
"excluded": [
{
"id": "notes.expired",
"reason": "expired"
},
{
"id": "notes.future",
"reason": "not-yet-valid"
}
],
"warnings": [
"stale"
],
"lifecycle": {
"notes.current": "current",
"notes.stale": "stale"
}
}
}

View file

@ -0,0 +1,14 @@
opencontext: "1.0"
id: lifecycle-test
name: Lifecycle
collections:
notes: ./context/notes/**
freshness:
default_ttl: 30d
roles:
everyone:
include:
- notes.*

View file

@ -0,0 +1,12 @@
---
id: policies.payroll
type: policy
layer: L3
authority: canonical
owner: finance
canonical_source: true
permissions:
read: [finance]
---
Payroll runs on the 25th.

View file

@ -0,0 +1,10 @@
---
id: policies.refunds
type: policy
layer: L3
authority: canonical
owner: support
canonical_source: true
---
Refunds within 30 days.

View file

@ -0,0 +1,32 @@
{
"description": "An object-level read grant narrows a role that would otherwise include it. Both roles include policies.*; only finance may read the payroll policy.",
"resolve": {
"role": "support",
"at": "2026-08-09T12:00:00Z"
},
"expect": {
"included": [
"policies.refunds"
],
"excluded": [
{
"id": "policies.payroll",
"reason": "permission-denied"
}
]
},
"also": [
{
"resolve": {
"role": "finance",
"at": "2026-08-09T12:00:00Z"
},
"expect": {
"included": [
"policies.payroll",
"policies.refunds"
]
}
}
]
}

View file

@ -0,0 +1,14 @@
opencontext: "1.0"
id: permissions-test
name: Object-level permissions
collections:
policies: ./context/policies/**
roles:
support:
include:
- policies.*
finance:
include:
- policies.*

View file

@ -0,0 +1,21 @@
{
"id": "customers.acme",
"type": "customer",
"layer": "L2",
"title": "ACME Inc.",
"authority": "reference",
"owner": "support",
"classification": "confidential",
"canonical_source": true,
"content": {
"name": "ACME Inc.",
"plan": "enterprise",
"ssn": "000-00-0000",
"contacts": [
{
"name": "Dana",
"email": "dana@acme.example"
}
]
}
}

View file

@ -0,0 +1,28 @@
{
"description": "Redaction runs after authorization: the consumer is entitled to the record, and still does not receive the SSN. The bundle discloses that redaction happened without disclosing what was redacted.",
"resolve": {
"role": "support",
"at": "2026-08-09T12:00:00Z"
},
"expect": {
"included": [
"customers.acme"
],
"redacted": {
"customers.acme": [
"ssn",
"contacts[*].email"
]
},
"contentAbsent": {
"customers.acme": [
"ssn"
]
},
"contentEquals": {
"customers.acme": {
"contacts.0.email": "[REDACTED]"
}
}
}
}

View file

@ -0,0 +1,19 @@
opencontext: "1.0"
id: redaction-test
name: Redaction
collections:
customers: ./context/customers/**
roles:
support:
include:
- customers.*
max_classification: confidential
redact:
- path: ssn
mode: remove
reason: PII
- path: contacts[*].email
mode: mask
replacement: "[REDACTED]"

View file

@ -0,0 +1,12 @@
---
id: pricing.enterprise
type: policy
layer: L3
version: 1
authority: canonical
owner: sales
canonical_source: true
updated: 2026-01-01T00:00:00Z
---
Enterprise plans start at $1,800/month.

View file

@ -0,0 +1,14 @@
---
id: pricing.enterprise
type: policy
layer: L3
version: 2
authority: canonical
owner: sales
canonical_source: true
updated: 2026-08-01T00:00:00Z
supersedes:
- pricing.enterprise@1
---
Enterprise plans start at $2,500/month.

View file

@ -0,0 +1,33 @@
{
"description": "Superseded versions are retained on disk and excluded from default resolution; --include-historical brings them back so a past view can be reconstructed.",
"resolve": {
"role": "sales",
"at": "2026-08-09T12:00:00Z"
},
"expect": {
"included": [
"pricing.enterprise"
],
"includedVersions": {
"pricing.enterprise": 2
},
"excluded": [
{
"id": "pricing.enterprise",
"reason": "superseded"
}
]
},
"also": [
{
"resolve": {
"role": "sales",
"at": "2026-08-09T12:00:00Z",
"includeHistorical": true
},
"expect": {
"objectCount": 2
}
}
]
}

View file

@ -0,0 +1,11 @@
opencontext: "1.0"
id: supersession-test
name: Supersession
collections:
pricing: ./context/pricing/**
roles:
sales:
include:
- pricing.*