code2okf 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. code2okf/SPEC.md +1006 -0
  2. code2okf/__init__.py +8 -0
  3. code2okf/cli.py +234 -0
  4. code2okf/clis/inspectmd/pyproject.toml +40 -0
  5. code2okf/clis/inspectmd/src/inspectmd/__init__.py +8 -0
  6. code2okf/clis/inspectmd/src/inspectmd/__main__.py +5 -0
  7. code2okf/clis/inspectmd/src/inspectmd/cli.py +159 -0
  8. code2okf/clis/inspectmd/src/inspectmd/parse.py +212 -0
  9. code2okf/clis/inspectokf/pyproject.toml +40 -0
  10. code2okf/clis/inspectokf/src/inspectokf/__init__.py +8 -0
  11. code2okf/clis/inspectokf/src/inspectokf/__main__.py +5 -0
  12. code2okf/clis/inspectokf/src/inspectokf/cli.py +104 -0
  13. code2okf/clis/merkleokf/pyproject.toml +40 -0
  14. code2okf/clis/merkleokf/src/merkleokf/__init__.py +8 -0
  15. code2okf/clis/merkleokf/src/merkleokf/__main__.py +5 -0
  16. code2okf/clis/merkleokf/src/merkleokf/cli.py +121 -0
  17. code2okf/clis/merkleokf/src/merkleokf/merkle.py +145 -0
  18. code2okf/clis/sizeokf/pyproject.toml +40 -0
  19. code2okf/clis/sizeokf/src/sizeokf/__init__.py +8 -0
  20. code2okf/clis/sizeokf/src/sizeokf/__main__.py +5 -0
  21. code2okf/clis/sizeokf/src/sizeokf/cli.py +93 -0
  22. code2okf/clis/sizeokf/src/sizeokf/sizes.py +155 -0
  23. code2okf/compile.py +267 -0
  24. code2okf/events.py +86 -0
  25. code2okf/kit/README.md +128 -0
  26. code2okf/kit/files/home/.local/lib/code2okf/mount-state.sh +48 -0
  27. code2okf/kit/files/home/.pi/agent/AGENTS.md +185 -0
  28. code2okf/kit/files/home/.pi/agent/models.json +84 -0
  29. code2okf/kit/files/home/.pi/agent/settings.json +7 -0
  30. code2okf/kit/files/home/.pi/agent/skills/compile-okf/SKILL.md +142 -0
  31. code2okf/kit/files/home/.pi/agent/skills/compile-okf/scripts/check-okf.sh +155 -0
  32. code2okf/kit/files/home/.pi/agent/skills/compile-okf/scripts/frontmatter-guard.py +289 -0
  33. code2okf/kit/files/home/.pi/agent/skills/curate-okf/SKILL.md +68 -0
  34. code2okf/kit/files/home/.pi/agent/skills/inspect-md/SKILL.md +52 -0
  35. code2okf/kit/files/home/.pi/agent/skills/inspect-okf/SKILL.md +47 -0
  36. code2okf/kit/files/home/.pi/agent/skills/merkle-okf/SKILL.md +59 -0
  37. code2okf/kit/files/home/.pi/agent/skills/size-okf/SKILL.md +52 -0
  38. code2okf/kit/spec.yaml +312 -0
  39. code2okf/resources.py +74 -0
  40. code2okf/sandbox.py +266 -0
  41. code2okf/workbench.py +572 -0
  42. code2okf-0.1.0.dist-info/METADATA +391 -0
  43. code2okf-0.1.0.dist-info/RECORD +48 -0
  44. code2okf-0.1.0.dist-info/WHEEL +4 -0
  45. code2okf-0.1.0.dist-info/entry_points.txt +2 -0
  46. code2okf-0.1.0.dist-info/licenses/LICENSE +21 -0
  47. code2okf-0.1.0.dist-info/licenses/LICENSE-OKF-SPEC.txt +203 -0
  48. code2okf-0.1.0.dist-info/licenses/NOTICE-OKF-SPEC.md +37 -0
code2okf/SPEC.md ADDED
@@ -0,0 +1,1006 @@
1
+ # Open Knowledge Format (OKF)
2
+
3
+ **Version 0.2**
4
+
5
+ OKF is an open, human- and agent-friendly format for representing
6
+ *knowledge*: the metadata, context, and curated insight that surrounds
7
+ data and systems. It is designed to be authored by people, generated by
8
+ agents, exchanged across organizations, and consumed by both.
9
+
10
+ The format is intentionally minimal: a directory of markdown files with
11
+ YAML frontmatter. There is no schema registry, no central authority, and
12
+ no required tooling. If you can `cat` a file, you can read OKF; if you
13
+ can `git clone` a repo, you can ship it.
14
+
15
+ This document is self-contained: it specifies everything needed to
16
+ produce and consume OKF v0.2. A summary of what changed from v0.1 is in
17
+ §13.
18
+
19
+ ---
20
+
21
+ ## 1. Motivation
22
+
23
+ The space of knowledge representation for AI agents is evolving quickly,
24
+ and many incompatible conventions are emerging. OKF takes the position
25
+ that knowledge is best represented in commonly accessible, established
26
+ formats that are:
27
+
28
+ - **Readable** by humans without tooling.
29
+ - **Parseable** by agents without bespoke SDKs.
30
+ - **Diffable** in version control.
31
+ - **Portable** across tools, organizations, and time.
32
+
33
+ Increasingly, a knowledge corpus is not authored once and then read: it
34
+ is **continuously written and maintained by agents**. When most concepts
35
+ are machine-generated, a consumer needs answers that a plain
36
+ markdown-plus-frontmatter convention does not make first-class:
37
+
38
+ 1. What was this created from, and how was it verified? (**provenance**)
39
+ 2. How much should I trust it? (**trust**)
40
+ 3. Is it still true? (**freshness**)
41
+ 4. Is it the current version? (**lifecycle**)
42
+ 5. Was this number produced the way we said it must be? (**attestation**)
43
+
44
+ OKF v0.2 makes provenance, trust, lifecycle, and attestation first-class
45
+ while keeping the format minimally opinionated. The format is minimally
46
+ opinionated. It standardizes only the small set of structural conventions
47
+ needed to make a knowledge corpus self-describing — anything beyond that
48
+ is left to the producer.
49
+
50
+ ### Goals
51
+
52
+ 1. Define a universal format that **producers** (people, agents, export
53
+ pipelines) can write into.
54
+ 2. Inform how **consumers** (agents, UIs, search indexes, deterministic
55
+ code) should read and traverse it.
56
+ 3. Facilitate **exchange** of knowledge across systems and organizations.
57
+ 4. Standardize the small set of frontmatter fields that make an
58
+ agent-maintained corpus **trustable**, without prescribing any runtime.
59
+
60
+ ### Non-goals
61
+
62
+ - Defining a fixed taxonomy of concept types.
63
+ - Prescribing storage, serving, or query infrastructure.
64
+ - Replacing domain-specific schemas (Avro, Protobuf, OpenAPI, and so on).
65
+ OKF *references* them; it does not subsume them.
66
+ - Specifying a packaging or invocation standard for the code an executor
67
+ or attester points at. OKF fixes the interface, not the packaging.
68
+
69
+ ---
70
+
71
+ ## 2. Terminology
72
+
73
+ - **Knowledge Bundle** (or **bundle**): A self-contained, hierarchical
74
+ collection of knowledge documents. The unit of distribution.
75
+ - **Concept**: A single unit of knowledge within a bundle, represented as
76
+ one markdown document. It may describe a tangible asset (a table, an
77
+ API), an abstract idea (a metric, a business process), or anything in
78
+ between.
79
+ - **Concept ID**: The path of the concept's file within the bundle, with
80
+ the `.md` suffix removed.
81
+ - **Frontmatter**: A YAML metadata block delimited by `---` at the top of
82
+ a markdown file.
83
+ - **Body**: Everything in the file after the frontmatter.
84
+ - **Link**: A standard markdown link from one concept to another, used to
85
+ express relationships beyond the implicit parent/child hierarchy.
86
+ - **Source**: A material a concept derives from, external or internal to
87
+ the bundle, recorded in the `sources` frontmatter field.
88
+ - **Provenance**: The set of sources a concept derives from.
89
+ - **Credibility signal**: An objective, per-source fact (`author`,
90
+ `usage_count`, `last_modified`) used to infer trust; OKF records the
91
+ signals, not a verdict (see §5.1).
92
+ - **Actor**: A string identifying who or what performed an action, using
93
+ the convention `<producer>/<version>` for agents, `human:<id>` for
94
+ people, and `process:<id>` for automated processes (see §7).
95
+ - **Trust tier**: A level derived from a concept's `verified` field:
96
+ unverified, machine-confirmed, or human-reviewed (see §5.3).
97
+ - **Attested Computation**: A concept (`type: Attested Computation`)
98
+ carrying a sanctioned way to compute a value, so a consumer can confirm
99
+ the value was produced by running it (see §10).
100
+ - **Executor**: Run instructions or code that executes a computation and
101
+ returns a receipt (see §10.2).
102
+ - **Receipt**: The evidence a run returns, shaped by `executor.receipt`; a
103
+ runtime artifact, not stored in the bundle (see §10).
104
+ - **Attester**: Deterministic (no-LLM) code that inspects a receipt and
105
+ returns a verdict (see §10.2).
106
+
107
+ ---
108
+
109
+ ## 3. Bundle structure
110
+
111
+ A bundle is a directory tree of markdown files. The directory structure
112
+ is independent of the domain: producers organize concepts however makes
113
+ sense for the knowledge being captured.
114
+
115
+ ```
116
+ path/to/bundle/
117
+ index.md # Optional. Directory listing for progressive disclosure.
118
+ log.md # Optional. Chronological history of updates.
119
+ <concept>.md # A concept at the bundle root.
120
+ <subdirectory>/ # Subdirectories organize concepts into groups.
121
+ index.md
122
+ <concept>.md
123
+ <subdirectory>/
124
+ ...
125
+ ```
126
+
127
+ A bundle MAY be distributed as:
128
+
129
+ - A git repository (recommended, since it provides history, attribution,
130
+ and diffs).
131
+ - A tarball or zip archive of the directory.
132
+ - A subdirectory within a larger repository.
133
+
134
+ ### 3.1 Reserved filenames
135
+
136
+ The following filenames have defined meaning at any level of the
137
+ hierarchy and MUST NOT be used for concept documents:
138
+
139
+ | Filename | Purpose |
140
+ |------------|----------------------------------|
141
+ | `index.md` | Directory listing. See §8. |
142
+ | `log.md` | Update history. See §9. |
143
+
144
+ All other `.md` files are concept documents.
145
+
146
+ Tags remain a first-class concept through the `tags` frontmatter field
147
+ (§4.1). OKF does not specify a separate file format for aggregating
148
+ documents by tag; a consumer that wants a tag-browsing view can
149
+ synthesize one at consumption time by scanning frontmatter.
150
+
151
+ ---
152
+
153
+ ## 4. Concept documents
154
+
155
+ Every concept is a UTF-8 markdown file with two parts:
156
+
157
+ 1. A **YAML frontmatter block**, delimited by `---` on its own line at the
158
+ start of the file and a closing `---` on its own line.
159
+ 2. A **markdown body**, containing free-form content.
160
+
161
+ ### 4.1 Frontmatter
162
+
163
+ ```yaml
164
+ ---
165
+ type: <Type name> # REQUIRED
166
+ title: <Optional display name>
167
+ description: <Optional one-line summary>
168
+ resource: <Optional canonical URI for the underlying asset>
169
+ tags: [<tag>, <tag>, ...] # Optional
170
+ # ... trust, lifecycle, provenance, and computation families (see §5, §10)
171
+ # ... other producer-defined key/value pairs
172
+ ---
173
+ ```
174
+
175
+ **Required:**
176
+
177
+ - `type`: A short string identifying the kind of concept. Consumers use it
178
+ for routing, filtering, and presentation. Example values:
179
+ `BigQuery Table`, `BigQuery Dataset`, `API Endpoint`, `Metric`,
180
+ `Playbook`, `Reference`, `Attested Computation`.
181
+
182
+ Type values are **not** registered centrally. Producers SHOULD pick
183
+ values that are descriptive and self-explanatory; consumers MUST
184
+ tolerate unknown types gracefully, typically by treating them as generic
185
+ concepts.
186
+
187
+ `type` is the only always-required key; a concept carrying just `type` is
188
+ fully conformant (§11).
189
+
190
+ **Recommended:**
191
+
192
+ - `title`: Human-readable display name. If omitted, consumers MAY derive a
193
+ title from the filename.
194
+ - `description`: A single sentence summarizing the concept. Used by
195
+ `index.md` generators, search snippets, and previews.
196
+ - `resource`: A URI that uniquely identifies the underlying asset the
197
+ concept describes. Absent for concepts that describe abstract ideas
198
+ rather than physical resources.
199
+ - `tags`: A YAML list of short strings for cross-cutting categorization.
200
+
201
+ The optional **provenance**, **trust**, and **lifecycle** families (§5) and
202
+ the **computation** fields for Attested Computation concepts (§10) may also
203
+ appear.
204
+
205
+ **Extensions:** Producers MAY include any additional keys. Consumers
206
+ SHOULD preserve unknown keys when round-tripping and MUST NOT reject
207
+ documents with unrecognized fields.
208
+
209
+ ### 4.2 Body
210
+
211
+ The body is standard markdown. Producers SHOULD favor structural markdown
212
+ (headings, lists, tables, fenced code blocks) over freeform prose, since
213
+ structure aids both human reading and agent retrieval.
214
+
215
+ There are no required body sections. The following headings have
216
+ **conventional** meaning and SHOULD be used when applicable:
217
+
218
+ | Heading | Purpose |
219
+ |-----------------|--------------------------------------------------------|
220
+ | `# Schema` | Structured description of an asset's columns/fields. |
221
+ | `# Examples` | Concrete usage examples, often as fenced code blocks. |
222
+ | `# Computation` | The sanctioned computation of an Attested Computation. See §10. |
223
+
224
+ Per-claim attribution to external sources uses markdown footnotes keyed to
225
+ `sources` entries rather than a body citations list (§5.1).
226
+
227
+ ### 4.3 Example: a concept bound to a resource
228
+
229
+ ```markdown
230
+ ---
231
+ type: BigQuery Table
232
+ title: Customer Orders
233
+ description: One row per completed customer order across all channels.
234
+ resource: https://console.cloud.google.com/bigquery?p=acme&d=sales&t=orders
235
+ tags: [sales, orders, revenue]
236
+ generated: { by: reference_agent/gemini-2.5-pro, at: 2026-05-28T14:30:00Z }
237
+ ---
238
+
239
+ # Schema
240
+
241
+ | Column | Type | Description |
242
+ |---------------|-----------|------------------------------------------|
243
+ | `order_id` | STRING | Globally unique order identifier. |
244
+ | `customer_id` | STRING | Foreign key into [customers](/tables/customers.md). |
245
+ | `total_usd` | NUMERIC | Order total in US dollars. |
246
+ | `placed_at` | TIMESTAMP | When the customer submitted the order. |
247
+
248
+ # Joins
249
+
250
+ Joined with [customers](/tables/customers.md) on `customer_id`.
251
+ ```
252
+
253
+ ### 4.4 Example: a concept not bound to a resource
254
+
255
+ ```markdown
256
+ ---
257
+ type: Playbook
258
+ title: "Incident response: data freshness alert"
259
+ description: Steps to triage a freshness alert on the orders pipeline.
260
+ tags: [oncall, incident]
261
+ generated: { by: human:ahormati, at: 2026-04-12T09:00:00Z }
262
+ ---
263
+
264
+ # Trigger
265
+
266
+ A freshness alert fires when `orders` lags more than 30 minutes behind its
267
+ expected SLA. See the [orders table](/tables/orders.md).
268
+
269
+ # Steps
270
+
271
+ 1. Check the [ingestion job dashboard](https://example.com/dash).
272
+ 2. ...
273
+ ```
274
+
275
+ ---
276
+
277
+ ## 5. Provenance, trust, and lifecycle
278
+
279
+ These frontmatter families make "where did this come from," "how much
280
+ should I trust it," and "is it still current" answerable from frontmatter.
281
+ All are optional. Their absence carries meaning: an unverified concept is
282
+ distinguishable from a verified one, but is never rejected (§11).
283
+
284
+ Every timestamp-valued key in OKF is an ISO 8601 datetime with an explicit
285
+ UTC offset, for example `2026-06-30T14:00:00Z`.
286
+
287
+ ### 5.1 Provenance: `sources`
288
+
289
+ `sources` records the materials a concept derives from, external or
290
+ internal to the bundle.
291
+
292
+ ```yaml
293
+ sources:
294
+ - id: ga4-schema
295
+ resource: https://developers.google.com/analytics/bigquery/export-schema
296
+ title: GA4 BigQuery Export schema
297
+ author: team:ga4-docs
298
+ usage_count: 5000
299
+ last_modified: 2026-05-30T00:00:00Z
300
+ usage_window: { from: 2026-06-01T00:00:00Z, to: 2026-06-30T00:00:00Z }
301
+ ```
302
+
303
+ Each `sources` entry:
304
+
305
+ - `resource`: REQUIRED within an entry. Names either a concrete artifact a
306
+ consumer can follow (an absolute URL, a bundle-relative path, or a path
307
+ into a `references/` subdirectory, §6) or a population or scope descriptor
308
+ it cannot (for example `all queries in BigQuery project X`).
309
+ - `id`: Optional. A stable key used to attribute individual claims (see
310
+ below). SHOULD be present when the body cites the source.
311
+ - `title`: Optional. Human-readable label for the source.
312
+ - The optional credibility signals `author`, `usage_count`, and
313
+ `last_modified`, described next.
314
+
315
+ **Source credibility signals.** OKF records objective, per-source signals
316
+ so a consumer can judge how much to trust a concept by judging the sources
317
+ it was extracted from. It does not store a credibility score: a score is
318
+ subjective, unportable across consumers, and goes stale. Credibility is
319
+ *inferred* from the signals, the same way trust tiers are (§5.3), not
320
+ stored. Each signal is optional and lives on a `sources` entry:
321
+
322
+ - `author`: Who or what produced the source, in the actor convention (§7).
323
+ An authority signal.
324
+ - `usage_count`: How often `resource` was exercised (dashboard views, query
325
+ executions, page reads) over `usage_window`. An adoption and liveness
326
+ signal. For a single artifact it is that artifact's own exercise count;
327
+ for a scope descriptor it is the number of exercises within the scope that
328
+ touch the concept.
329
+ - `last_modified`: When the source itself last changed. A recency signal,
330
+ distinct from `generated.at` (§5.2), which records when the concept was
331
+ written.
332
+ - `usage_window`: Written once as a sibling of `sources`, it frames every
333
+ `usage_count` with a `{ from, to }` datetime range. A single entry MAY
334
+ carry its own `usage_window` to override the shared one.
335
+
336
+ `usage_count` is a coarse signal. It is comparable at the
337
+ alive-versus-dead and order-of-magnitude level, and against a source's own
338
+ history over time, but not as a precise cross-kind ranking: a scheduled
339
+ query's executions and a human's deliberate dashboard views do not carry
340
+ equal weight. Consumers SHOULD read it as liveness and trend, not as a
341
+ score.
342
+
343
+ Lineage is expressed through links, not a dedicated field. When a
344
+ `resource` points at another OKF concept, the derivation edge already
345
+ exists in the bundle graph (§6), so a consumer MAY recurse into that
346
+ source's own `sources` and let credibility propagate. External leaf sources
347
+ carry only their intrinsic signals. Deeper lineage (an explicit external
348
+ `derived_from`, or data lineage) is out of scope for v0.2.
349
+
350
+ **Per-claim attribution.** To attribute a specific claim, use a markdown
351
+ footnote whose label is a `sources[].id`:
352
+
353
+ ```markdown
354
+ The `events_` table is sharded daily as `events_YYYYMMDD`.[^ga4-schema]
355
+
356
+ [^ga4-schema]: GA4 BigQuery Export schema
357
+ ```
358
+
359
+ The footnote label is the join key into `sources`; consumers resolve
360
+ attribution through the matching entry, not by parsing the footnote prose.
361
+ Labels are keyed rather than positional (`sources[0]`) because agents
362
+ constantly rewrite these documents: a positional index misattributes
363
+ silently the moment the list is reordered, whereas a stable `id` survives
364
+ reordering.
365
+
366
+ ### 5.2 Trust: `generated` and `verified`
367
+
368
+ `generated` records how the current content was produced. `verified`
369
+ records who or what has confirmed the content against its sources or
370
+ `resource`. They are kept distinct because who *wrote* a concept need not
371
+ be who *confirmed* it.
372
+
373
+ ```yaml
374
+ generated: { by: reference_agent/gemini-2.5-pro, at: 2026-06-20T22:53:05Z }
375
+ ```
376
+
377
+ - `generated.by`: REQUIRED within `generated`. An actor (§7).
378
+ - `generated.at`: An ISO 8601 datetime marking the content's last
379
+ meaningful change. Consumers use it to tell a recent edit from a stale
380
+ fact.
381
+
382
+ ```yaml
383
+ verified:
384
+ - { by: human:ahormati, at: 2026-06-25T09:00:00Z }
385
+ - { by: process:finance-nightly, at: 2026-06-26T02:00:00Z }
386
+ ```
387
+
388
+ - `verified`: A list of verification events, each with `by` (an actor) and
389
+ `at` (an ISO 8601 datetime). Multiple entries capture independent
390
+ checks, for example a human sign-off plus a nightly process. "How
391
+ recently" is the latest `at`.
392
+ - `verified` is independent of `generated.at`: content can change without
393
+ re-confirmation, and facts can be re-confirmed without regeneration.
394
+ - A single verifier MAY be written as one `{ by, at }` mapping without the
395
+ list dash. Consumers MUST treat a bare mapping as a one-element list:
396
+
397
+ ```yaml
398
+ verified: { by: human:ahormati, at: 2026-06-25T09:00:00Z }
399
+ ```
400
+
401
+ ### 5.3 Trust tiers
402
+
403
+ Consumers derive a trust tier from `verified`, lowest to highest:
404
+
405
+ - No `verified` key ⇒ **unverified**.
406
+ - `verified` by non-`human:` actors only ⇒ **machine-confirmed**.
407
+ - `verified` by a `human:<id>` actor ⇒ **human-reviewed**.
408
+
409
+ A concept with no trust frontmatter is still consumable; consumers MUST
410
+ NOT reject it (§11). Trust tiers are advisory signals, not access control.
411
+
412
+ ### 5.4 Lifecycle: `status`
413
+
414
+ ```yaml
415
+ status: stable # draft | stable | deprecated
416
+ ```
417
+
418
+ - `draft`: not yet reviewed; possibly incomplete.
419
+ - `stable`: default; ready for consumption.
420
+ - `deprecated`: kept for links and history; no longer current.
421
+
422
+ Absent `status` ⇒ `stable`.
423
+
424
+ ### 5.5 Lifecycle: `stale_after`
425
+
426
+ ```yaml
427
+ stale_after: 2026-09-23T00:00:00Z # content is stale on/after this instant
428
+ ```
429
+
430
+ Optional. An absolute instant. A concept is stale when
431
+ `now >= stale_after`. An absolute instant, not a relative TTL, keeps the
432
+ staleness decision a plain comparison with no reference to when the
433
+ concept was read.
434
+
435
+ ---
436
+
437
+ ## 6. Cross-linking and paths
438
+
439
+ ### 6.1 Links between concepts
440
+
441
+ Concepts MAY link to other concepts using standard markdown links. Two
442
+ forms are supported:
443
+
444
+ - **Absolute (bundle-relative):** begins with `/`, interpreted relative to
445
+ the bundle root. This is the **recommended** form because it is stable
446
+ when documents are moved within their subdirectory.
447
+
448
+ ```markdown
449
+ See the [customers table](/tables/customers.md) for the join key.
450
+ ```
451
+
452
+ - **Relative:** a standard markdown relative path.
453
+
454
+ ```markdown
455
+ See the [neighboring concept](./other.md).
456
+ ```
457
+
458
+ A link from concept A to concept B asserts a *relationship*. The specific
459
+ kind (parent/child, references, joins-with, depends-on) is conveyed by the
460
+ surrounding prose, not by the link itself. Consumers that build a graph
461
+ view typically treat all links as directed edges of an untyped
462
+ relationship.
463
+
464
+ Consumers MUST tolerate broken links: a link whose target does not exist
465
+ in the bundle is not malformed; it may simply represent not-yet-written
466
+ knowledge.
467
+
468
+ ### 6.2 Path-valued fields
469
+
470
+ Several fields name a path or URI: `resource`, `sources[].resource`,
471
+ `computation`, `executor.resource`, and `attester.resource` (§10). A
472
+ `sources[].resource` may instead be a scope descriptor (§5.1), in which
473
+ case it is not a path. Each path-valued field accepts:
474
+
475
+ - an absolute URL (for example `https://...`),
476
+ - a bundle-relative path beginning with `/`, or
477
+ - a relative path (for example `../computations/revenue.md`).
478
+
479
+ ### 6.3 The `references/` convention
480
+
481
+ A `references/` subdirectory conventionally mirrors external material, run
482
+ instructions, or code as first-class concepts within the bundle. Sources,
483
+ executors, and attesters commonly point into it (for example
484
+ `references/attesters/revenue.py`). It is a naming convention, not a
485
+ requirement.
486
+
487
+ ---
488
+
489
+ ## 7. Actor convention
490
+
491
+ Fields that record an identity (`generated.by`, `verified[].by`) use a
492
+ single actor convention:
493
+
494
+ - `<producer>/<version>` for agents and tools, for example
495
+ `reference_agent/gemini-2.5-pro`.
496
+ - `human:<id>` for a person, for example `human:ahormati`.
497
+ - `process:<id>` for an automated process, for example
498
+ `process:finance-nightly`.
499
+
500
+ Consumers that classify trust (§5.3) key off the `human:` prefix, so
501
+ producers MUST use it for hand-authored or human-confirmed content.
502
+
503
+ ---
504
+
505
+ ## 8. Index files
506
+
507
+ An `index.md` file MAY appear in any directory, including the bundle root.
508
+ It enumerates the directory's contents to support **progressive
509
+ disclosure**: letting a human or agent see what is available before
510
+ opening individual documents.
511
+
512
+ Index files contain no frontmatter, with one exception: a bundle-root
513
+ `index.md` MAY carry an `okf_version` key (§12). The body uses one or more
514
+ sections, each grouping concepts under a heading:
515
+
516
+ ```markdown
517
+ # Section / Group Heading
518
+
519
+ * [Title 1](relative-url-1) - short description of item 1
520
+ * [Title 2](relative-url-2) - short description of item 2
521
+
522
+ # Another Section
523
+
524
+ * [Subdirectory](subdir/) - short description of the subdirectory
525
+ ```
526
+
527
+ Entries SHOULD include the description from the linked concept's
528
+ frontmatter. Producers MAY generate `index.md` automatically; consumers
529
+ MAY synthesize one on the fly when none is present.
530
+
531
+ ---
532
+
533
+ ## 9. Log files
534
+
535
+ A `log.md` file MAY appear at any level of the hierarchy to record the
536
+ history of changes to that scope. The format is a flat list of
537
+ date-grouped entries, newest first:
538
+
539
+ ```markdown
540
+ # Directory Update Log
541
+
542
+ ## 2026-05-22
543
+ * **Update**: Added a BigQuery table reference for [Customer Metrics](/tables/customer-metrics.md).
544
+ * **Creation**: Established the [Dataplex Playbook](/playbooks/dataplex.md).
545
+
546
+ ## 2026-05-15
547
+ * **Initialization**: Created foundational directory structure.
548
+ ```
549
+
550
+ Date headings MUST use ISO 8601 `YYYY-MM-DD` form. Log entries are prose;
551
+ the leading bold word (`**Update**`, `**Creation**`, `**Deprecation**`) is
552
+ a convention, not a requirement.
553
+
554
+ ---
555
+
556
+ ## 10. Attested computations concept
557
+
558
+ An Attested Computation concept carries not just what a value *means* but a
559
+ sanctioned way to *compute* it, so a consumer can confirm the agent ran the
560
+ blessed computation instead of improvising its own. Provenance (§5.1)
561
+ answers "where did this claim come from"; attestation answers "was this
562
+ number produced the way we said it must be." OKF records the computation
563
+ and the means to check it; it does not execute anything itself.
564
+
565
+ ### 10.1 A computation is its own concept
566
+
567
+ A sanctioned computation is a standalone concept of
568
+ `type: Attested Computation`. A concept that needs the value (a `Metric`, a
569
+ `BigQuery Table`) links to it with a normal markdown link (§6). Three
570
+ properties motivate the standalone concept:
571
+
572
+ - **`runtime` defines what `parameters` mean.** A parameter is a SQL bind
573
+ variable, a dbt var, or a Python argument depending on the runtime.
574
+ Keeping `runtime` and `parameters` in one frontmatter makes the binding
575
+ semantics self-evident.
576
+ - **One computation, many consumers.** The same computation can back a
577
+ metric, a dashboard concept, and a report; as a concept it is referenced
578
+ once and reused.
579
+ - **Trust state is per computation.** `verified`, `stale_after`, and a
580
+ single `attester` describe one thing. Revenue, profit, and margin each
581
+ verify and attest independently, which is three concepts, not three
582
+ entries in one frontmatter.
583
+
584
+ ### 10.2 Contract fields
585
+
586
+ The contract is the concept's top-level frontmatter. In addition to the
587
+ provenance, trust, and lifecycle families (§5), an Attested Computation
588
+ concept carries:
589
+
590
+ - `runtime`: REQUIRED for this type. The single field that says how to run
591
+ the computation, and so how the executor and attester interpret it and
592
+ what `parameters` mean. Example values: `bigquery`, `postgres`, `dbt`,
593
+ `python`, `Looker`.
594
+ - `parameters`: A list of the typed, named holes the agent may fill. Each
595
+ entry: `{ name, type, required }`. Binding semantics follow `runtime`.
596
+ - `computation`: Optional. A path (§6.2) to a file holding the
597
+ computation, used instead of an inline body fence (see §10.3). Absent ⇒
598
+ the body `# Computation` fence is the computation.
599
+ - `executor`: How the computation is run. `resource` names run
600
+ instructions or code; a runner (an agent, or deterministic consumer
601
+ code) follows it. `receipt` declares the fields a run must return, the
602
+ evidence the attester inspects (for example a BigQuery `job_id` and the
603
+ SQL the job actually executed).
604
+ - `attester`: The deterministic check. `resource` names code (no LLM) that
605
+ takes a receipt and returns a verdict. It is meant to run consumer-side.
606
+
607
+ What sits behind a `resource` (a Skill, a script, a container) is a
608
+ packaging choice; OKF fixes the interface, not the packaging (§1).
609
+
610
+ ```markdown
611
+ ---
612
+ type: Attested Computation
613
+ title: Revenue for fiscal year
614
+ description: Recognized revenue for a fiscal year, per Finance's definition.
615
+ status: stable
616
+ runtime: bigquery
617
+ parameters:
618
+ - { name: year, type: integer, required: true }
619
+ executor:
620
+ resource: references/skills/run-on-bq.md
621
+ receipt: [job_id, executed_sql, result]
622
+ attester:
623
+ resource: references/attesters/revenue.py
624
+ generated: { by: reference_agent/gemini-2.5-pro, at: 2026-06-20T22:53:05Z }
625
+ verified: { by: human:ahormati, at: 2026-06-25T09:00:00Z }
626
+ stale_after: 2026-09-23T00:00:00Z
627
+ sources:
628
+ - id: rev-policy
629
+ resource: https://wiki.acme/finance/revenue-recognition
630
+ title: Revenue recognition policy
631
+ ---
632
+
633
+ # Computation
634
+
635
+ SELECT SUM(amount) AS revenue
636
+ FROM finance.recognized_revenue
637
+ WHERE fiscal_year = @year
638
+
639
+ The computation binds only the declared `parameters`, per the recognition
640
+ policy.[^rev-policy]
641
+
642
+ [^rev-policy]: Revenue recognition policy
643
+ ```
644
+
645
+ ### 10.3 The computation
646
+
647
+ Provide the computation in one of two ways:
648
+
649
+ - **Inline:** a single fenced code block in the body under `# Computation`.
650
+ Best for a short computation reviewed alongside the contract.
651
+ - **File:** set `computation` to a path (§6.2) and omit the body fence.
652
+ Best for a long or generated computation, or one already kept as a real
653
+ file shared with non-OKF tooling.
654
+
655
+ ```yaml
656
+ runtime: bigquery
657
+ computation: references/computations/lib/revenue.sql
658
+ parameters:
659
+ - { name: year, type: integer, required: true }
660
+ ```
661
+
662
+ The agent MAY only supply *values* for the declared `parameters`; it MUST
663
+ NOT author or edit the computation. Binding `computation` with the
664
+ parameter values into the executable artifact is the consumer's job, and
665
+ the attester independently re-derives that same binding to compare against
666
+ what actually ran. Because the comparison is on the expanded, compiled
667
+ artifact the receipt carries (`executed_sql`, `compiled_sql`), a rewritten
668
+ query, a swapped computation file, or a mutated dependency fails the check.
669
+ A typed, parameter-only surface is what makes "did the sanctioned thing
670
+ run" a mechanical comparison rather than a judgement call.
671
+
672
+ ### 10.4 Concepts that use a computation
673
+
674
+ A document is rarely a single computation. An income-statement overview
675
+ that discusses revenue, profit, and margin stays one readable concept and
676
+ links to one Attested Computation per figure:
677
+
678
+ ```markdown
679
+ ---
680
+ type: Metric
681
+ title: Revenue
682
+ description: Recognized revenue for a fiscal year.
683
+ tags: [finance, revenue]
684
+ status: stable
685
+ generated: { by: reference_agent/gemini-2.5-pro, at: 2026-06-20T22:53:05Z }
686
+ ---
687
+
688
+ # Definition
689
+
690
+ Recognized revenue sums `amount` over rows booked to the fiscal year,
691
+ computed by [the revenue computation](../computations/revenue.md).
692
+ ```
693
+
694
+ Because each computation is its own concept, revenue can be fresh while
695
+ profit is past its `stale_after`, and each attests on its own run.
696
+ Co-locating them is a directory choice (a `computations/` folder with an
697
+ `index.md`), not a frontmatter one.
698
+
699
+ ### 10.5 How a consumer uses it (informative)
700
+
701
+ This subsection is informative, not normative. The runtime artifacts below
702
+ are **not** stored in the bundle.
703
+
704
+ 1. **Discover** via `type: Attested Computation`, a frontmatter signal
705
+ liftable into `index.md`; a consumer reaches one directly or by
706
+ following a link from a concept that uses it.
707
+ 2. **Load** the contract from frontmatter and the computation from the
708
+ body (or the file named by `computation`).
709
+ 3. **Parameterize**: the agent supplies values for the declared parameters.
710
+ 4. **Execute**: the executor runs the bound computation and returns a
711
+ receipt shaped by `executor.receipt`.
712
+ 5. **Attest**: the consumer runs the attester over the receipt. It
713
+ confirms provenance (the computation that ran equals `computation` bound
714
+ with the claimed parameters, not agent-authored SQL) and fidelity (the
715
+ displayed value matches the receipt's authoritative source, re-read by
716
+ job id rather than taken from the agent's text).
717
+ 6. **Gate**: refuse to display a failing attestation; warn or refuse when
718
+ `now >= stale_after`. On success, surface the verdict (for example a
719
+ link to the job log) so trust is visible.
720
+
721
+ ### 10.6 Verification versus attestation
722
+
723
+ `verified` (§5.2) and attestation are distinct, and both exist:
724
+
725
+ - `verified` confirms the *definition* still matches policy. It is
726
+ doc-level, slow, and recorded in the bundle.
727
+ - Attestation confirms a single *run* produced the value the sanctioned
728
+ way. It is per-call, runtime, and not stored in the bundle.
729
+
730
+ A concept with a stale definition can still attest cleanly, and a
731
+ freshly-verified definition still requires attestation on each run, which
732
+ is why both are needed.
733
+
734
+ ---
735
+
736
+ ## 11. Conformance
737
+
738
+ A bundle is **conformant** with OKF v0.2 if:
739
+
740
+ 1. Every non-reserved `.md` file in the tree contains a parseable YAML
741
+ frontmatter block.
742
+ 2. Every frontmatter block contains a non-empty `type` field.
743
+ 3. Every reserved filename (`index.md`, `log.md`) follows the structure in
744
+ §8 and §9 respectively when present.
745
+
746
+ When the trust, lifecycle, provenance, or computation families are
747
+ present, producers SHOULD follow §5 through §10, and consumers:
748
+
749
+ - MUST treat a bare `verified` mapping as a one-element list (§5.2).
750
+ - MUST NOT reject a concept for missing any optional family (§5.3).
751
+ - SHOULD derive trust tiers and staleness only from the fields specified
752
+ here, and SHOULD surface, not silently drop, a failing attestation
753
+ (§10.5).
754
+
755
+ Consumers SHOULD treat all other constraints as soft guidance. In
756
+ particular, consumers MUST NOT reject a bundle because of:
757
+
758
+ - Missing optional frontmatter fields.
759
+ - Unknown `type` values.
760
+ - Unknown additional frontmatter keys.
761
+ - Broken cross-links.
762
+ - Missing `index.md` files.
763
+
764
+ ---
765
+
766
+ ## 12. Versioning
767
+
768
+ This document specifies OKF version **0.2**. Revisions are versioned as
769
+ `<major>.<minor>`:
770
+
771
+ - A **minor** version bump introduces backward-compatible additions (new
772
+ optional fields, new conventional section headings).
773
+ - A **major** version bump may make breaking changes (renaming required
774
+ fields, changing reserved filenames).
775
+
776
+ Bundles MAY declare the version they target with `okf_version: "0.2"` in a
777
+ bundle-root `index.md` frontmatter block (the only place frontmatter is
778
+ permitted in an `index.md`). Consumers that do not understand the declared
779
+ version SHOULD attempt best-effort consumption rather than refusing the
780
+ bundle.
781
+
782
+ ### Considered and deferred
783
+
784
+ The following are intentionally left to a future revision:
785
+
786
+ - The full runtime protocol: receipt and verdict wire formats, and the
787
+ attestation lifecycle around a run.
788
+ - The attester ABI, portability, and sandboxing, likely bundled with
789
+ future work on serving and Skills.
790
+ - Attestation caching.
791
+ - Semantic-layer templates (Looker, dbt) where the attester comparison
792
+ shifts from SQL equality to model-and-binding equality.
793
+
794
+ ---
795
+
796
+ ## 13. Changes from v0.1
797
+
798
+ v0.2 supersedes OKF v0.1 and is a minor version bump under §12, except for
799
+ two deliberate breaking changes called out below because they rename or
800
+ retire v0.1 fields. A v0.1 bundle is consumable by a v0.2 consumer under
801
+ the fallbacks noted here.
802
+
803
+ ### 13.1 Breaking changes
804
+
805
+ - **`timestamp` is superseded by `generated.at`.** A concept's last
806
+ content change is now recorded as `generated: { by, at }` (§5.2).
807
+ Consumers MAY fall back to a legacy `timestamp` when `generated` is
808
+ absent.
809
+ - **The body `# Citations` list is superseded by `sources`.** Provenance
810
+ moves to frontmatter (§5.1). Consumers SHOULD read `sources` and MAY
811
+ still parse a legacy `# Citations` body list for v0.1 documents.
812
+
813
+ ### 13.2 Additive changes
814
+
815
+ All of the following are additive: new optional keys, one new concept
816
+ type, and one new conventional heading. Their absence yields a plain v0.1
817
+ concept.
818
+
819
+ - New frontmatter families: `sources` with its per-source credibility
820
+ signals (`author`, `usage_count`, `last_modified`) and the `usage_window`
821
+ sibling; `generated`, `verified`; `status`, `stale_after` (§5).
822
+ - New concept type `Attested Computation` and its computation keys
823
+ `runtime`, `parameters`, `computation`, `executor`, `attester` (§10).
824
+ - New conventional body heading `# Computation` (§4.2).
825
+ - The actor convention for `generated.by` and `verified[].by` (§7).
826
+
827
+ Everything else (bundle structure, reserved filenames, the required
828
+ `type`, recommended `title`/`description`/`resource`/`tags`, cross-linking,
829
+ index files, log files, permissive conformance) is carried forward
830
+ unchanged.
831
+
832
+ ---
833
+
834
+ ## Appendix A: Worked example, an income statement
835
+
836
+ One bundle exercising every family, shown as a v0.1 to v0.2 migration of an
837
+ income statement with two figures, revenue and gross profit.
838
+
839
+ ### v0.1 form
840
+
841
+ A single doc: both figures in one concept, the SQL in prose an agent can
842
+ read, ignore, or rewrite, citations a flat list, and the only timestamp is
843
+ `timestamp`.
844
+
845
+ ```markdown
846
+ ---
847
+ type: Metric
848
+ title: Income statement (fiscal year)
849
+ description: Headline income-statement figures for a fiscal year.
850
+ tags: [finance, income-statement]
851
+ timestamp: '2026-05-28T22:53:05+00:00'
852
+ ---
853
+
854
+ # Definition
855
+ The income statement reports revenue and gross profit for a fiscal year.
856
+
857
+ # Revenue
858
+ Recognized revenue sums `amount` over rows booked to the fiscal year:
859
+
860
+ SELECT SUM(amount) AS revenue
861
+ FROM finance.recognized_revenue
862
+ WHERE fiscal_year = <year>
863
+
864
+ # Gross profit
865
+ Gross profit by segment, per the cost-allocation standard:
866
+
867
+ SELECT gross_profit FROM fct_income_statement
868
+ WHERE fiscal_year = <year> AND segment = <segment>
869
+
870
+ # Citations
871
+ - https://wiki.acme/finance/fpa-handbook
872
+ - https://wiki.acme/finance/revenue-recognition
873
+ - https://wiki.acme/finance/cost-allocation
874
+ ```
875
+
876
+ ### v0.2 form
877
+
878
+ The two figures split into attested computations linked from a narrative
879
+ concept. Every family is populated, and the two computations sit in
880
+ deliberately different states so one consumer reaches two verdicts.
881
+
882
+ ```
883
+ bundles/finance/
884
+ metrics/income-statement.md type: Metric (narrates, links both)
885
+ computations/revenue.md type: Attested Computation (runtime: bigquery)
886
+ computations/profit.md type: Attested Computation (runtime: dbt)
887
+ references/skills/run-on-bq.md, run-dbt.md
888
+ references/attesters/sql-equality.py, dbt-binding.py
889
+ ```
890
+
891
+ `metrics/income-statement.md`, the readable doc; trust lives on what it
892
+ links, not here:
893
+
894
+ ```markdown
895
+ ---
896
+ type: Metric
897
+ title: Income statement (fiscal year)
898
+ description: Headline income-statement figures for a fiscal year.
899
+ tags: [finance, income-statement]
900
+ status: stable
901
+ generated: { by: reference_agent/gemini-2.5-pro, at: 2026-06-20T22:53:05Z }
902
+ verified: { by: human:ahormati, at: 2026-06-25T09:00:00Z }
903
+ stale_after: 2026-12-31T00:00:00Z
904
+ sources:
905
+ - id: fpa-handbook
906
+ resource: https://wiki.acme/finance/fpa-handbook
907
+ title: FP&A reporting handbook
908
+ ---
909
+
910
+ # Definition
911
+ The income statement reports [revenue](../computations/revenue.md) and
912
+ [gross profit](../computations/profit.md) for a fiscal year, per the FP&A
913
+ reporting handbook.[^fpa-handbook] Each figure is produced by a sanctioned,
914
+ attestable computation; this concept only narrates them.
915
+
916
+ [^fpa-handbook]: FP&A reporting handbook
917
+ ```
918
+
919
+ `computations/revenue.md`, BigQuery SQL, human-verified, fresh, and
920
+ corroborated by a live dashboard source carrying credibility signals:
921
+
922
+ ```markdown
923
+ ---
924
+ type: Attested Computation
925
+ title: Revenue for fiscal year
926
+ description: Recognized revenue for a fiscal year, per Finance's definition.
927
+ tags: [finance, revenue]
928
+ status: stable
929
+ runtime: bigquery
930
+ parameters:
931
+ - { name: year, type: integer, required: true }
932
+ executor:
933
+ resource: references/skills/run-on-bq.md
934
+ receipt: [job_id, executed_sql, result]
935
+ attester:
936
+ resource: references/attesters/sql-equality.py
937
+ generated: { by: reference_agent/gemini-2.5-pro, at: 2026-06-28T14:00:00Z }
938
+ verified: { by: human:ahormati, at: 2026-06-25T09:00:00Z }
939
+ stale_after: 2026-12-31T00:00:00Z
940
+ sources:
941
+ - id: rev-policy
942
+ resource: https://wiki.acme/finance/revenue-recognition
943
+ title: Revenue recognition policy
944
+ author: team:finance-fpa
945
+ last_modified: 2026-04-02T00:00:00Z
946
+ - id: exec-rev-dash
947
+ resource: dashboards/exec-revenue
948
+ title: Executive revenue dashboard
949
+ author: team:finance-fpa
950
+ usage_count: 5000
951
+ last_modified: 2026-06-18T00:00:00Z
952
+ usage_window: { from: 2026-06-01T00:00:00Z, to: 2026-06-30T00:00:00Z }
953
+ ---
954
+
955
+ # Computation
956
+
957
+ SELECT SUM(amount) AS revenue
958
+ FROM finance.recognized_revenue
959
+ WHERE fiscal_year = @year
960
+
961
+ Recognized revenue per the recognition policy,[^rev-policy] corroborated by
962
+ the executive revenue dashboard.[^exec-rev-dash]
963
+
964
+ [^rev-policy]: Revenue recognition policy
965
+ [^exec-rev-dash]: Executive revenue dashboard
966
+ ```
967
+
968
+ `computations/profit.md`, a dbt model, process-verified, and past its
969
+ `stale_after`:
970
+
971
+ ```markdown
972
+ ---
973
+ type: Attested Computation
974
+ title: Gross profit for fiscal year
975
+ description: Gross profit by segment for a fiscal year, per the cost-allocation standard.
976
+ tags: [finance, profit]
977
+ status: stable
978
+ runtime: dbt
979
+ parameters:
980
+ - { name: year, type: integer, required: true }
981
+ - { name: segment, type: string, required: true }
982
+ executor:
983
+ resource: references/skills/run-dbt.md
984
+ receipt: [run_id, compiled_sql, result]
985
+ attester:
986
+ resource: references/attesters/dbt-binding.py
987
+ generated: { by: reference_agent/gemini-2.5-pro, at: 2026-06-14T14:00:00Z }
988
+ verified: { by: process:finance-nightly, at: 2026-06-12T08:00:00Z }
989
+ stale_after: 2026-06-15T00:00:00Z
990
+ sources:
991
+ - id: cost-alloc
992
+ resource: https://wiki.acme/finance/cost-allocation
993
+ title: Cost allocation standard
994
+ ---
995
+
996
+ # Computation
997
+
998
+ SELECT gross_profit
999
+ FROM {{ ref('fct_income_statement') }}
1000
+ WHERE fiscal_year = {{ var('year') }}
1001
+ AND segment = {{ var('segment') }}
1002
+
1003
+ Gross profit by segment per the cost-allocation standard.[^cost-alloc]
1004
+
1005
+ [^cost-alloc]: Cost allocation standard
1006
+ ```