@okfit/core 0.14.0 → 0.16.0

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.
@@ -0,0 +1,43 @@
1
+ import { DateTime, Duration, Option } from "effect";
2
+
3
+ // src/GeneratedAtFuture.ts
4
+ /**
5
+ * How far past now a `generated.at` may sit before okfit treats it as a future stamp: five minutes, the allowance for
6
+ * ordinary clock skew between machines. The lint `generated-at-future` and the repair in `okfit sync` both read it
7
+ * through {@link generatedAtIsFuture}.
8
+ *
9
+ * @public
10
+ */
11
+ const GENERATED_AT_TOLERANCE = Duration.minutes(5);
12
+ /**
13
+ * {@link GENERATED_AT_TOLERANCE} in words ("5 minutes"), for messages. Derived from the constant, so changing the
14
+ * tolerance changes every message that names it. The tolerance is a whole number of minutes.
15
+ *
16
+ * @public
17
+ */
18
+ const GENERATED_AT_TOLERANCE_TEXT = (() => {
19
+ const minutes = Duration.toMinutes(GENERATED_AT_TOLERANCE);
20
+ return `${minutes} minute${minutes === 1 ? "" : "s"}`;
21
+ })();
22
+ /**
23
+ * Whether `generatedAt` is more than {@link GENERATED_AT_TOLERANCE} later than `now`. Exactly the tolerance is not
24
+ * future; one millisecond more is.
25
+ *
26
+ * @public
27
+ */
28
+ const generatedAtIsFuture = (generatedAt, now) => DateTime.isGreaterThan(generatedAt, DateTime.addDuration(now, GENERATED_AT_TOLERANCE));
29
+ /**
30
+ * The earliest verification time `V` with `startOf(now, "second") <= V < generatedAt`, the verifications that
31
+ * re-stamping `generatedAt` down to now would turn from not current into current (OKF 0.3 §5.3). `okfit sync` skips
32
+ * such a re-stamp; the lint `generated-at-future` names the verification instead of promising the repair. `now` is
33
+ * truncated to the whole second because stamps are written in whole seconds. None when no verification falls in the
34
+ * window.
35
+ *
36
+ * @public
37
+ */
38
+ const verificationBlockingRestamp = (verifiedAts, generatedAt, now) => {
39
+ const from = DateTime.startOf(now, "second");
40
+ return verifiedAts.filter((at) => !DateTime.isLessThan(at, from) && DateTime.isLessThan(at, generatedAt)).reduce((earliest, at) => Option.isSome(earliest) && !DateTime.isLessThan(at, earliest.value) ? earliest : Option.some(at), Option.none());
41
+ };
42
+
43
+ export { GENERATED_AT_TOLERANCE, GENERATED_AT_TOLERANCE_TEXT, generatedAtIsFuture, verificationBlockingRestamp };
package/Graph.js CHANGED
@@ -1,6 +1,8 @@
1
1
  import { Graph as Graph$1, Option, Schema } from "effect";
2
+ import { Derive } from "./Derive.js";
2
3
  import { DiagnosticRange } from "./Diagnostic.js";
3
4
  import { frontmatterFieldSpan, pathFieldsOf, resolvePathField, resolveTarget } from "./internal/links.js";
5
+ import { OkfVersion } from "./OkfVersion.js";
4
6
 
5
7
  // src/Graph.ts
6
8
  /**
@@ -117,14 +119,17 @@ var LinkGraph = class LinkGraph {
117
119
  }
118
120
  };
119
121
  const indexes = /* @__PURE__ */ new WeakMap();
122
+ /** Builds the lookup sets and the version-gated root fallback for one loaded bundle: the single place the gate is computed. */
123
+ const buildIndex = (bundle) => ({
124
+ files: new Set(bundle.files),
125
+ concepts: new Set(bundle.concepts.keys()),
126
+ rootFallback: OkfVersion.legacyFallbacks(bundle)
127
+ });
120
128
  /** The lookup sets for one loaded bundle, built once: a bundle is immutable after load. */
121
129
  const indexOf = (bundle) => {
122
130
  const cached = indexes.get(bundle);
123
131
  if (cached !== void 0) return cached;
124
- const built = {
125
- files: new Set(bundle.files),
126
- concepts: new Set(bundle.concepts.keys())
127
- };
132
+ const built = buildIndex(bundle);
128
133
  indexes.set(bundle, built);
129
134
  return built;
130
135
  };
@@ -133,25 +138,55 @@ const indexOf = (bundle) => {
133
138
  *
134
139
  * @public
135
140
  */
136
- var Graph = class {
141
+ var Graph = class Graph {
137
142
  constructor() {}
138
143
  /**
139
144
  * Pure. Resolve `raw`, written in the file at bundle-relative `from`, the way the graph does; `field`
140
- * applies the path-field rules (a `sources.resource` descriptor).
145
+ * applies the path-field rules (a `sources.resource` descriptor). `rule` (default `"declared"`) states which
146
+ * root-fallback rule applies; it is applied per call and never cached.
141
147
  */
142
- static resolve = (bundle, from, raw, field) => {
143
- const lookup = indexOf(bundle);
148
+ static resolve = (bundle, from, raw, field, rule = "declared") => {
149
+ const declared = indexOf(bundle);
150
+ const lookup = rule === "declared" ? declared : {
151
+ ...declared,
152
+ rootFallback: rule === "legacy"
153
+ };
144
154
  return field === void 0 ? resolveTarget(from, raw, lookup) : resolvePathField(from, field, raw, lookup);
145
155
  };
146
156
  /**
157
+ * Pure. The concept that replaces a deprecated concept (OKF 0.3 section 5.4): follow `superseded_by` from `id`
158
+ * through deprecated concepts to the first concept whose derived status is neither `deprecated` nor `unknown`
159
+ * (a `draft` or `stable` concept is current knowledge). `None` when `id` is not a deprecated concept, a link
160
+ * resolves to a non-concept or a missing target, a deprecated concept has no `superseded_by`, the chain ends at
161
+ * an `unknown`-status concept, or the chain revisits a concept (a cycle or a self-reference). Resolution is the
162
+ * one {@link Graph.resolve} performs, so a bare value in a v0.2 bundle resolves through the root fallback.
163
+ *
164
+ * @public
165
+ */
166
+ static replacement = (bundle, id) => {
167
+ const visited = /* @__PURE__ */ new Set();
168
+ let current = bundle.concepts.get(id);
169
+ while (current !== void 0) {
170
+ const status = Derive.status(current.frontmatter);
171
+ if (status !== "deprecated") return visited.size === 0 || status === "unknown" ? Option.none() : Option.some(current.id);
172
+ if (visited.has(current.id)) return Option.none();
173
+ visited.add(current.id);
174
+ const raw = current.frontmatter.superseded_by;
175
+ if (raw === void 0) return Option.none();
176
+ const resolved = Graph.resolve(bundle, current.path, raw, "superseded_by");
177
+ if (resolved._tag !== "node" || resolved.kind !== "concept") return Option.none();
178
+ const next = bundle.concepts.get(resolved.id);
179
+ if (next === void 0 || visited.has(next.id)) return Option.none();
180
+ current = next;
181
+ }
182
+ return Option.none();
183
+ };
184
+ /**
147
185
  * Pure. Body links come from `document.links`, path fields from the frontmatter (D-23, D-24).
148
186
  * Placeholder `missing` nodes are added before their edge because `Graph.addEdge` throws on an absent endpoint.
149
187
  */
150
188
  static fromBundle = (bundle) => {
151
- const lookup = {
152
- files: new Set(bundle.files),
153
- concepts: new Set(bundle.concepts.keys())
154
- };
189
+ const lookup = indexOf(bundle);
155
190
  const index = /* @__PURE__ */ new Map();
156
191
  const graph = Graph$1.directed((mutable) => {
157
192
  const node = (id, kind) => {
package/IndexDocument.js CHANGED
@@ -16,14 +16,23 @@ var IndexSection = class extends Schema.Class("IndexSection")({
16
16
  range: DiagnosticRange
17
17
  }) {};
18
18
  /**
19
- * A parsed `index.md` (D-21). `okfVersion` is present only on the bundle root.
19
+ * A parsed `index.md` (D-21). The metadata fields are present only on the bundle root (OKF 0.3 section 8.1):
20
+ * `okfVersion`, `title`, `description` and `license` are the typed reads, `metadata` is the whole decoded
21
+ * mapping (extension keys included) and `frontmatter` is the raw YAML text between the fences.
20
22
  * @public
21
23
  */
22
24
  var IndexDocument = class extends Schema.Class("IndexDocument")({
23
25
  path: Schema.String,
24
26
  dir: Schema.String,
25
27
  okfVersion: Schema.optionalKey(Schema.String),
26
- sections: Schema.Array(IndexSection)
28
+ title: Schema.optionalKey(Schema.String),
29
+ description: Schema.optionalKey(Schema.String),
30
+ license: Schema.optionalKey(Schema.String),
31
+ metadata: Schema.optionalKey(Schema.Record(Schema.String, Schema.Unknown)),
32
+ frontmatter: Schema.optionalKey(Schema.String),
33
+ sections: Schema.Array(IndexSection),
34
+ /** The file's text as the load read it (a leading byte-order mark dropped); absent on a hand-built document. */
35
+ source: Schema.optionalKey(Schema.String)
27
36
  }) {};
28
37
 
29
38
  export { IndexDocument, IndexEntry, IndexSection };
package/Integrity.js CHANGED
@@ -12,6 +12,17 @@ const DIGEST_RE = /^[0-9a-f]{16}$/u;
12
12
  */
13
13
  const Digest = Schema.String.pipe(Schema.check(Schema.isPattern(DIGEST_RE, { message: "Expected a lowercase 16-character hex digest" })));
14
14
  /**
15
+ * The prefix of every frontmatter key okfit owns (OKF v0.3 section 4.1 extension keys).
16
+ * @public
17
+ */
18
+ const OKFIT_KEY_PREFIX = "x-okfit-";
19
+ /**
20
+ * The top-level frontmatter key that holds okfit's {@link Integrity} family.
21
+ * Every reader and writer of that key goes through this constant.
22
+ * @public
23
+ */
24
+ const INTEGRITY_KEY = `${OKFIT_KEY_PREFIX}integrity`;
25
+ /**
15
26
  * The body digest as of `generated.at`.
16
27
  * @public
17
28
  */
@@ -27,7 +38,7 @@ var IntegrityVerified = class extends Schema.Class("IntegrityVerified")({
27
38
  }) {};
28
39
  /**
29
40
  * okfit's own top-level frontmatter family, the only place okfit stores digests
30
- * (OKF v0.2 section 4.1 extension key). Spec families such as `generated` and
41
+ * (OKF v0.3 section 4.1 extension key). Spec families such as `generated` and
31
42
  * `verified` stay exactly as the spec defines them.
32
43
  * @public
33
44
  */
@@ -36,4 +47,4 @@ var Integrity = class extends Schema.Class("Integrity")({
36
47
  verified: Schema.optionalKey(IntegrityVerified)
37
48
  }) {};
38
49
 
39
- export { Digest, Integrity, IntegrityGenerated, IntegrityVerified };
50
+ export { Digest, INTEGRITY_KEY, Integrity, IntegrityGenerated, IntegrityVerified, OKFIT_KEY_PREFIX };
package/LogDocument.js CHANGED
@@ -21,7 +21,9 @@ var LogDocument = class extends Schema.Class("LogDocument")({
21
21
  path: Schema.String,
22
22
  dir: Schema.String,
23
23
  title: Schema.optionalKey(Schema.String),
24
- groups: Schema.Array(LogGroup)
24
+ groups: Schema.Array(LogGroup),
25
+ /** The file's text as the load read it (a leading byte-order mark dropped); absent on a hand-built document. */
26
+ source: Schema.optionalKey(Schema.String)
25
27
  }) {};
26
28
 
27
29
  export { LogDocument, LogGroup, LogItem };
package/OkfVersion.js ADDED
@@ -0,0 +1,43 @@
1
+ import { Option } from "effect";
2
+
3
+ // src/OkfVersion.ts
4
+ const VERSION = /^(\d+)\.(\d+)$/;
5
+ const LEGACY = {
6
+ major: 0,
7
+ minor: 2
8
+ };
9
+ /**
10
+ * Reads and compares the OKF version a bundle declares. The declared version is the bundle-root
11
+ * `index.md`'s `okf_version`; one gate, {@link OkfVersion.legacyFallbacks}, decides whether the v0.2
12
+ * fallbacks apply. @public
13
+ */
14
+ var OkfVersion = class OkfVersion {
15
+ constructor() {}
16
+ /** Parses exactly `<major>.<minor>` (no `v`, no patch, no whitespace); anything else is `None`. */
17
+ static parse = (raw) => {
18
+ const match = VERSION.exec(raw);
19
+ return match === null ? Option.none() : Option.some({
20
+ major: Number(match[1]),
21
+ minor: Number(match[2])
22
+ });
23
+ };
24
+ /** Compares numerically, major first, so `0.10` sorts after `0.9`. */
25
+ static compare = (a, b) => a.major !== b.major ? a.major < b.major ? -1 : 1 : a.minor === b.minor ? 0 : a.minor < b.minor ? -1 : 1;
26
+ /**
27
+ * The version the bundle-root `index.md` declares, as written; `None` when there is no root index or no `okf_version`.
28
+ * An unquoted number is its source text (`0.10`, not `0.1`).
29
+ */
30
+ static declared = (bundle) => Option.fromNullishOr(bundle.indexes.get("")?.okfVersion);
31
+ /** True when nothing is declared or the declared version parses and is 0.2 or earlier; an unparsable version reads as current. */
32
+ static allowsLegacyFallbacks = (declared) => Option.match(declared, {
33
+ onNone: () => true,
34
+ onSome: (raw) => Option.match(OkfVersion.parse(raw), {
35
+ onNone: () => false,
36
+ onSome: (version) => OkfVersion.compare(version, LEGACY) <= 0
37
+ })
38
+ });
39
+ /** Whether the v0.2 fallbacks apply to this bundle: `allowsLegacyFallbacks(declared(bundle))`. */
40
+ static legacyFallbacks = (bundle) => OkfVersion.allowsLegacyFallbacks(OkfVersion.declared(bundle));
41
+ };
42
+
43
+ export { OkfVersion };
package/OkfitConfig.js CHANGED
@@ -1,8 +1,11 @@
1
1
  import { ConfigFile, ConfigMerge } from "@effected/config-file";
2
2
  import { TomlCodec } from "@effected/config-file/toml";
3
+ import { GlobPattern } from "@effected/glob";
3
4
  import { HostedSchema } from "@effected/schemastore";
4
- import { Duration, Effect, Option, Schema, SchemaGetter, SchemaIssue, SchemaTransformation } from "effect";
5
+ import { Duration, Effect, Option, Result, Schema, SchemaGetter, SchemaIssue, SchemaTransformation } from "effect";
5
6
  import { Actor, ActorPattern } from "./Actor.js";
7
+ import { GENERATED_AT_TOLERANCE_TEXT } from "./GeneratedAtFuture.js";
8
+ import { INTEGRITY_KEY, OKFIT_KEY_PREFIX } from "./Integrity.js";
6
9
 
7
10
  // src/OkfitConfig.ts
8
11
  /**
@@ -129,12 +132,12 @@ const TagDeclaration = Schema.Struct({ description: Schema.optionalKey(Schema.St
129
132
  const LintTable = Schema.Struct({
130
133
  broken_links: Schema.optionalKey(LintLevel.annotate({
131
134
  title: "broken-links",
132
- description: "A link in a concept's body or frontmatter does not resolve. Default \"warn\".",
135
+ description: "A link in a concept's body or a path field in its frontmatter does not resolve, or names a #heading its target concept does not have. Default \"warn\".",
133
136
  default: "warn"
134
137
  })),
135
138
  missing_index: Schema.optionalKey(LintLevel.annotate({
136
139
  title: "missing-index",
137
- description: "A concept-holding directory has no index.md. Default \"warn\".",
140
+ description: "A concept-holding directory has no index.md file in the bundle (an index.md that exists but fails to load is reported by its own error instead). Default \"warn\".",
138
141
  default: "warn"
139
142
  })),
140
143
  unknown_type: Schema.optionalKey(LintLevel.annotate({
@@ -157,9 +160,14 @@ const LintTable = Schema.Struct({
157
160
  description: "A concept whose type sets require_verified = true carries no verified entry and is not a draft. Default \"error\".",
158
161
  default: "error"
159
162
  })),
163
+ verified_before_change: Schema.optionalKey(LintLevel.annotate({
164
+ title: "verified-before-change",
165
+ description: "A concept has verification events, but the ones at or after generated.at give a lower trust tier than all of them would: the content changed after it was verified (OKF 0.3 §5.3, \"verified before the last change\"). Draft, deprecated and unknown-status concepts are exempt. Default \"warn\".",
166
+ default: "warn"
167
+ })),
160
168
  family_invalid: Schema.optionalKey(LintLevel.annotate({
161
169
  title: "family-invalid",
162
- description: "A concept's declared family does not match an accepted shape. Default \"error\".",
170
+ description: `okfit's own ${INTEGRITY_KEY} family does not match its shape. Default "error".`,
163
171
  default: "error"
164
172
  })),
165
173
  computation_runtime_missing: Schema.optionalKey(LintLevel.annotate({
@@ -184,17 +192,17 @@ const LintTable = Schema.Struct({
184
192
  })),
185
193
  actor_prefix_unknown: Schema.optionalKey(LintLevel.annotate({
186
194
  title: "actor-prefix-unknown",
187
- description: "An actor's prefix is not human, process, or a producer shape. Default \"info\".",
195
+ description: "An actor in generated.by, verified[].by or sources[].author uses a scheme other than human, team, process or a producer shape; it is accepted and read as non-human. Default \"info\".",
188
196
  default: "info"
189
197
  })),
190
198
  actor_email: Schema.optionalKey(LintLevel.annotate({
191
199
  title: "actor-email",
192
- description: "An actor in generated.by, verified[].by, integrity.verified.by or [actors].humans contains \"@\", so an email address or domain is stored in the bundle or its config. Use a human:<id> without the domain. Default \"warn\".",
200
+ description: `An actor in generated.by, verified[].by, ${INTEGRITY_KEY}.verified.by or [actors].humans contains "@", so an email address or domain is stored in the bundle or its config. Use a human:<id> without the domain. Default "warn".`,
193
201
  default: "warn"
194
202
  })),
195
203
  verified_actor_unknown: Schema.optionalKey(LintLevel.annotate({
196
204
  title: "verified-actor-unknown",
197
- description: "A human verified[].by or integrity.verified.by matches no entry of a non-empty [actors].humans. Silent when the list is empty. Default \"warn\".",
205
+ description: `A human verified[].by or ${INTEGRITY_KEY}.verified.by matches no entry of a non-empty [actors].humans. Silent when the list is empty. Default "warn".`,
198
206
  default: "warn"
199
207
  })),
200
208
  legacy_timestamp: Schema.optionalKey(LintLevel.annotate({
@@ -207,6 +215,11 @@ const LintTable = Schema.Struct({
207
215
  description: "The config file declares a top-level key the schema does not recognize. Default \"warn\".",
208
216
  default: "warn"
209
217
  })),
218
+ config_okf_version_stale: Schema.optionalKey(LintLevel.annotate({
219
+ title: "config-okf-version-stale",
220
+ description: "The config sets okf_version and the bundle-root index.md declares a different one; the index decides how the bundle reads, so the config value is stale. Default \"warn\".",
221
+ default: "warn"
222
+ })),
210
223
  stale: Schema.optionalKey(LintLevel.annotate({
211
224
  title: "stale",
212
225
  description: "A concept is past its stale_after instant. Default \"info\".",
@@ -217,6 +230,26 @@ const LintTable = Schema.Struct({
217
230
  description: "A directory in the bundle could not be read while walking. Default \"warn\".",
218
231
  default: "warn"
219
232
  })),
233
+ read_changed: Schema.optionalKey(LintLevel.annotate({
234
+ title: "read-changed",
235
+ description: "A file in the bundle was replaced while it was being read, so it was left out of this load; reading again may succeed. Output derived from the changed file is held back: its own stamp, and the indexes and log that would list it. Default \"warn\".",
236
+ default: "warn"
237
+ })),
238
+ frontmatter_missing: Schema.optionalKey(LintLevel.annotate({
239
+ title: "frontmatter-missing",
240
+ description: "A .md file other than index.md or log.md has no frontmatter, so it is not a concept and is skipped (OKF 0.3 §3.2). Default \"warn\".",
241
+ default: "warn"
242
+ })),
243
+ type_missing: Schema.optionalKey(LintLevel.annotate({
244
+ title: "type-missing",
245
+ description: "A .md file's frontmatter has no non-empty string type, so it is not a concept and is skipped (OKF 0.3 §3.2). Default \"warn\".",
246
+ default: "warn"
247
+ })),
248
+ symlink_escape: Schema.optionalKey(LintLevel.annotate({
249
+ title: "symlink-escape",
250
+ description: "A file or directory in the bundle is a symbolic link whose target lies outside the bundle root or cannot be resolved (a missing target, a link loop, an unreadable target); it is not read, nothing under it is walked, and it is not part of the bundle. Pruned directory names such as node_modules are not checked, and hidden ones only when hidden files are included (OKF 0.3 §3.2). Default \"warn\".",
251
+ default: "warn"
252
+ })),
220
253
  generated_at_drift: Schema.optionalKey(LintLevel.annotate({
221
254
  title: "generated-at-drift",
222
255
  description: "A committed concept's generated.at is missing or does not match its last body-changing commit, and is not otherwise authoritative (issue #19: a stamp recorded during the unchanged-body run survives a squash/rebase merge). Default \"warn\".",
@@ -224,7 +257,7 @@ const LintTable = Schema.Struct({
224
257
  })),
225
258
  verified_drift: Schema.optionalKey(LintLevel.annotate({
226
259
  title: "verified-drift",
227
- description: "A concept's latest human verification no longer covers its current content: the body or authored frontmatter changed since, the binding (integrity.verified) is missing, a later human entry is unbound, or the bound verifier is not in a non-empty [actors].humans. Draft and deprecated concepts are exempt, since okfit verify refuses them. A signal to re-verify, not a gate. Default \"warn\".",
260
+ description: `A concept's latest human verification no longer covers its current content: the body or authored frontmatter changed since, the binding (${INTEGRITY_KEY}.verified) is missing, a later human entry is unbound, or the bound verifier is not in a non-empty [actors].humans. Draft and deprecated concepts are exempt, since okfit verify refuses them. A signal to re-verify, not a gate. Default "warn".`,
228
261
  default: "warn"
229
262
  })),
230
263
  status_missing: Schema.optionalKey(LintLevel.annotate({
@@ -247,31 +280,112 @@ const LintTable = Schema.Struct({
247
280
  description: "A resource or sources[].resource path names a file that exists locally but git does not track yet; not raised once the file is staged (issue #279). Skipped outside a git repository and under --skip-provenance. Default \"warn\".",
248
281
  default: "warn"
249
282
  })),
283
+ resource_outside_project: Schema.optionalKey(LintLevel.annotate({
284
+ title: "resource-outside-project",
285
+ description: "A resource value resolves outside the project root, directly or through a symlink, so okfit never reads, stats or asks git about the target (okfit's repository check, not OKF). Default \"info\".",
286
+ default: "info"
287
+ })),
288
+ superseded_by_orphan: Schema.optionalKey(LintLevel.annotate({
289
+ title: "superseded-by-orphan",
290
+ description: "A concept carries superseded_by but its status is not deprecated; superseded_by has a meaning only with status: deprecated (OKF 0.3 §5.4). Default \"warn\".",
291
+ default: "warn"
292
+ })),
293
+ superseded_by_unresolved: Schema.optionalKey(LintLevel.annotate({
294
+ title: "superseded-by-unresolved",
295
+ description: "A deprecated concept's superseded_by resolves to an asset, an external value or the concept itself rather than a replacement concept (OKF 0.3 §5.4). A missing target is reported by broken-links. Default \"warn\".",
296
+ default: "warn"
297
+ })),
250
298
  generated_missing: Schema.optionalKey(LintLevel.annotate({
251
299
  title: "generated-missing",
252
- description: "A concept has no generated block while actors.agent is configured, so okfit sync cannot stamp generated.at until the block exists (issue #73). Default \"warn\"; silent when actors.agent is unset.",
300
+ description: "A concept has no readable generated block (none, one written without a readable generated.by, or only a legacy timestamp) while actors.agent is configured; okfit sync creates one that is unwritten or a plain null, and the others need a hand edit (issue #73). Default \"warn\"; silent when actors.agent is unset.",
301
+ default: "warn"
302
+ })),
303
+ computation_missing: Schema.optionalKey(LintLevel.annotate({
304
+ title: "computation-missing",
305
+ description: "An Attested Computation has no computation: no computation key, and nothing in its Computation section that the bundle's OKF version reads as one (under 0.3 the first fenced block, §10.3; under 0.2 the text of a top-level section), so it is not attestable. Default \"warn\".",
306
+ default: "warn"
307
+ })),
308
+ generated_at_future: Schema.optionalKey(LintLevel.annotate({
309
+ title: "generated-at-future",
310
+ description: `A concept's generated.at is more than ${GENERATED_AT_TOLERANCE_TEXT} later than now, so no verification can count yet (OKF 0.3 §5.3) and okfit verify refuses it; run okfit sync, which re-stamps it to now (commit any edits to it first). Default "warn".`,
253
311
  default: "warn"
254
312
  })),
255
313
  publication_drift: Schema.optionalKey(LintLevel.annotate({
256
314
  title: "publication-drift",
257
- description: "A Publication's renders[].body is missing or no longer matches the current body of the concept it names, so the published page may restate stale facts. Default \"warn\".",
315
+ description: `A Publication's ${OKFIT_KEY_PREFIX}renders[].body is missing or no longer matches the current body of the concept it names, so the published page may restate stale facts. Default "warn".`,
258
316
  default: "warn"
259
317
  })),
260
318
  publication_orphan: Schema.optionalKey(LintLevel.annotate({
261
319
  title: "publication-orphan",
262
- description: "A Publication's surface or renders[].path does not resolve to a concept, or renders is not a list of { path, body } entries. Default \"error\".",
320
+ description: `A Publication's ${OKFIT_KEY_PREFIX}surface or ${OKFIT_KEY_PREFIX}renders[].path does not resolve to a concept, or ${OKFIT_KEY_PREFIX}renders is not a list of { path, body } entries. Default "error".`,
263
321
  default: "error"
264
322
  })),
265
323
  surface_unmatched: Schema.optionalKey(LintLevel.annotate({
266
324
  title: "surface-unmatched",
267
325
  description: "A Surface's resource glob matches no file or directory; legitimate in a brand-new monorepo, so it only warns. Default \"warn\".",
268
326
  default: "warn"
327
+ })),
328
+ index_metadata_invalid: Schema.optionalKey(LintLevel.annotate({
329
+ title: "index-metadata-invalid",
330
+ description: "The bundle-root index.md frontmatter carries an okf_version that is not a quoted <major>.<minor> string, or a title, description or license that is not a string; the value is read best-effort. Default \"warn\".",
331
+ default: "warn"
332
+ })),
333
+ entry_ignored: Schema.optionalKey(LintLevel.annotate({
334
+ title: "entry-ignored",
335
+ description: "An entry or mapping the spec defines (a sources, verified or parameters entry, generated) lacks a REQUIRED key or has one okfit cannot read, so it is ignored (OKF 0.3 §11.2 rule 3). Default \"warn\".",
336
+ default: "warn"
337
+ })),
338
+ value_malformed: Schema.optionalKey(LintLevel.annotate({
339
+ title: "value-malformed",
340
+ description: "A defined value okfit cannot read in its defined shape (wrong type, unparsable timestamp, malformed optional key) is read as absent; a malformed stale_after reads as malformed, never fresh (OKF 0.3 §5.5, §11.2). Default \"warn\".",
341
+ default: "warn"
342
+ })),
343
+ value_unknown: Schema.optionalKey(LintLevel.annotate({
344
+ title: "value-unknown",
345
+ description: "A defined key carries a value outside its vocabulary (today: status); the value is kept and the concept is not read as current knowledge (OKF 0.3 §5.4, §11.2 rule 4). Default \"warn\".",
346
+ default: "warn"
347
+ })),
348
+ non_concept_unlisted: Schema.optionalKey(LintLevel.annotate({
349
+ title: "non-concept-unlisted",
350
+ description: "A .md file is not a concept (no frontmatter, or no type) and matches no glob in [bundle] non_concepts. An okfit opinion, not OKF conformance (§3.2 allows such files). Silent when non_concepts is absent. Default \"warn\".",
351
+ default: "warn"
269
352
  }))
270
353
  }).annotate({
271
354
  title: "Lint severities",
272
355
  description: "Per-code severity overrides. Any key omitted keeps its default."
273
356
  });
274
357
  /**
358
+ * Scan a glob once, left to right, for a `[` or `{` that never closes; the
359
+ * result is the rejection message tail naming the opener, or `undefined` when
360
+ * none is left open. A backslash escapes the next character; a class closes at
361
+ * the first `]` after at least one member, where a leading `!` or `^` is not a
362
+ * member (so `[]a]` and `[!]a]` are classes but `[]` and `[!]` are not) and a
363
+ * POSIX `[:name:]` inside it is one unit; a `{` inside a class is literal;
364
+ * braces are counted by depth. A stray `]` or `}` is literal text.
365
+ */
366
+ const unclosedGlobMessage = (glob) => {
367
+ let depth = 0;
368
+ let classStart = -1;
369
+ let firstMember = -1;
370
+ for (let i = 0; i < glob.length; i++) {
371
+ const ch = glob[i];
372
+ if (ch === "\\") i++;
373
+ else if (classStart >= 0) {
374
+ if (ch === "[" && glob[i + 1] === ":") {
375
+ let j = i + 2;
376
+ while (j < glob.length && /[a-z]/.test(glob[j] ?? "")) j++;
377
+ if (j > i + 2 && glob[j] === ":" && glob[j + 1] === "]") i = j + 1;
378
+ } else if (ch === "]" && i > firstMember) classStart = -1;
379
+ } else if (ch === "[") {
380
+ classStart = i;
381
+ firstMember = glob[i + 1] === "!" || glob[i + 1] === "^" ? i + 2 : i + 1;
382
+ } else if (ch === "{") depth++;
383
+ else if (ch === "}" && depth > 0) depth--;
384
+ }
385
+ if (classStart >= 0) return `"[" opens a character class that never closes; to match a literal bracket write '\\[' in single quotes or "\\\\[" in double quotes`;
386
+ return depth > 0 ? `"{" opens a brace group that never closes; to match a literal brace write '\\{' in single quotes or "\\\\{" in double quotes` : void 0;
387
+ };
388
+ /**
275
389
  * The `OkfitConfig` struct schema. Exported only so the `OkfitConfigFields`
276
390
  * type below is reachable from the rollup; the barrel never re-exports this
277
391
  * value, so it stays out of the named public surface.
@@ -280,9 +394,8 @@ const LintTable = Schema.Struct({
280
394
  const okfitConfigFields = Schema.Struct({
281
395
  okf_version: Schema.optionalKey(Schema.String.annotate({
282
396
  title: "OKF spec version",
283
- description: "The Open Knowledge Format spec version this bundle targets.",
284
- default: "0.2",
285
- examples: ["0.2"]
397
+ description: "The okf_version okfit writes into a bundle-root index.md that declares none (okfit init, okfit sync). The bundle's own declaration decides how it is read. When the root index.md declares a different version, the lint config-okf-version-stale reports this value as stale.",
398
+ examples: ["0.3"]
286
399
  })),
287
400
  bundle: Schema.optionalKey(Schema.Struct({
288
401
  path: Schema.optionalKey(Schema.String.annotate({
@@ -296,6 +409,16 @@ const okfitConfigFields = Schema.Struct({
296
409
  description: "The named profile merged under `DEFAULTS < profile < file`, or \"none\" to disable profile merging.",
297
410
  default: "software-project",
298
411
  examples: ["software-project", "none"]
412
+ })),
413
+ non_concepts: Schema.optionalKey(Schema.Array(Schema.String.check(Schema.makeFilter((value) => {
414
+ const unclosed = unclosedGlobMessage(value);
415
+ if (unclosed !== void 0) return `Expected a valid glob pattern, got ${JSON.stringify(value)}: ${unclosed}`;
416
+ const compiled = GlobPattern.compileResult(value);
417
+ return Result.isSuccess(compiled) || `Expected a valid glob pattern, got ${JSON.stringify(value)}`;
418
+ }))).annotate({
419
+ title: "Non-concept Markdown",
420
+ description: "Globs, relative to the bundle root, of .md files that may have no frontmatter or no type (OKF 0.3 §3.2 lets a bundle hold README.md, AGENTS.md, CONTRIBUTING.md and SKILL.md). A `[` or `{` that never closes is rejected; to match the character itself write '\\[' in single quotes or \"\\\\[\" in double quotes. When set, any other typeless .md is the lint non-concept-unlisted, and the okfit plugin's hook stops an agent writing one. Absent: no restriction.",
421
+ examples: [["**/README.md", "**/AGENTS.md"]]
299
422
  }))
300
423
  }).annotate({
301
424
  title: "Bundle location and profile",
@@ -438,6 +561,7 @@ const LINT_KEY = {
438
561
  "required-key-missing": "required_key_missing",
439
562
  "field-value-unknown": "field_value_unknown",
440
563
  "require-verified-unmet": "require_verified_unmet",
564
+ "verified-before-change": "verified_before_change",
441
565
  "family-invalid": "family_invalid",
442
566
  "computation-runtime-missing": "computation_runtime_missing",
443
567
  "footnote-source-unknown": "footnote_source_unknown",
@@ -448,18 +572,33 @@ const LINT_KEY = {
448
572
  "verified-actor-unknown": "verified_actor_unknown",
449
573
  "legacy-timestamp": "legacy_timestamp",
450
574
  "config-unknown-key": "config_unknown_key",
575
+ "config-okf-version-stale": "config_okf_version_stale",
451
576
  stale: "stale",
452
577
  "walk-unreadable": "walk_unreadable",
578
+ "read-changed": "read_changed",
453
579
  "generated-at-drift": "generated_at_drift",
454
580
  "verified-drift": "verified_drift",
455
581
  "status-missing": "status_missing",
456
582
  "source-resource-missing": "source_resource_missing",
457
583
  "resource-ignored": "resource_ignored",
458
584
  "resource-untracked": "resource_untracked",
585
+ "resource-outside-project": "resource_outside_project",
586
+ "superseded-by-orphan": "superseded_by_orphan",
587
+ "superseded-by-unresolved": "superseded_by_unresolved",
459
588
  "generated-missing": "generated_missing",
589
+ "computation-missing": "computation_missing",
590
+ "generated-at-future": "generated_at_future",
460
591
  "publication-drift": "publication_drift",
461
592
  "publication-orphan": "publication_orphan",
462
- "surface-unmatched": "surface_unmatched"
593
+ "surface-unmatched": "surface_unmatched",
594
+ "index-metadata-invalid": "index_metadata_invalid",
595
+ "entry-ignored": "entry_ignored",
596
+ "value-malformed": "value_malformed",
597
+ "value-unknown": "value_unknown",
598
+ "frontmatter-missing": "frontmatter_missing",
599
+ "type-missing": "type_missing",
600
+ "symlink-escape": "symlink_escape",
601
+ "non-concept-unlisted": "non_concept_unlisted"
463
602
  };
464
603
  const DEFAULT_LINT = {
465
604
  broken_links: "warn",
@@ -468,6 +607,7 @@ const DEFAULT_LINT = {
468
607
  required_key_missing: "error",
469
608
  field_value_unknown: "error",
470
609
  require_verified_unmet: "error",
610
+ verified_before_change: "warn",
471
611
  family_invalid: "error",
472
612
  computation_runtime_missing: "error",
473
613
  footnote_source_unknown: "warn",
@@ -478,18 +618,33 @@ const DEFAULT_LINT = {
478
618
  verified_actor_unknown: "warn",
479
619
  legacy_timestamp: "info",
480
620
  config_unknown_key: "warn",
621
+ config_okf_version_stale: "warn",
481
622
  stale: "info",
482
623
  walk_unreadable: "warn",
624
+ read_changed: "warn",
483
625
  generated_at_drift: "warn",
484
626
  verified_drift: "warn",
485
627
  status_missing: "off",
486
628
  source_resource_missing: "warn",
487
629
  resource_ignored: "error",
488
630
  resource_untracked: "warn",
631
+ resource_outside_project: "info",
632
+ superseded_by_orphan: "warn",
633
+ superseded_by_unresolved: "warn",
489
634
  generated_missing: "warn",
635
+ computation_missing: "warn",
636
+ generated_at_future: "warn",
490
637
  publication_drift: "warn",
491
638
  publication_orphan: "error",
492
- surface_unmatched: "warn"
639
+ surface_unmatched: "warn",
640
+ index_metadata_invalid: "warn",
641
+ entry_ignored: "warn",
642
+ value_malformed: "warn",
643
+ value_unknown: "warn",
644
+ frontmatter_missing: "warn",
645
+ type_missing: "warn",
646
+ symlink_escape: "warn",
647
+ non_concept_unlisted: "warn"
493
648
  };
494
649
  const toSeverity = (level) => level === "warn" ? "warning" : level;
495
650
  const severityFor = (config, code) => {
@@ -510,7 +665,6 @@ const deepFreeze = (value) => {
510
665
  return value;
511
666
  };
512
667
  const DEFAULTS = deepFreeze({
513
- okf_version: "0.2",
514
668
  bundle: {
515
669
  path: "okf",
516
670
  profile: "software-project"
@@ -528,7 +682,8 @@ const DEFAULTS = deepFreeze({
528
682
  });
529
683
  const read = (path) => ConfigFile.read(path, {
530
684
  schema: OkfitConfigWire,
531
- codec: TomlCodec
685
+ codec: TomlCodec,
686
+ parseOptions: { errors: "all" }
532
687
  }).pipe(Effect.withSpan("OkfitConfig.read", { attributes: { path } }));
533
688
  /**
534
689
  * The okfit config codec and its statics (spec 4.2, D-28 to D-31).
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @okfit/core
2
2
 
3
- Spec-level [Open Knowledge Format (OKF)](https://github.com/GoogleCloudPlatform/open-knowledge-format/blob/main/SPEC.md) v0.2 support for [Effect](https://effect.website): frontmatter schemas, bundle loading, the concept link graph, trust and staleness derivation, and conformance validation.
3
+ Spec-level [Open Knowledge Format (OKF)](https://github.com/open-knowledge-format/open-knowledge-format/blob/main/SPEC.md) v0.3 support for [Effect](https://effect.website): frontmatter schemas, bundle loading, the concept link graph, trust and staleness derivation, and conformance validation.
4
4
 
5
5
  > **Pre-release.** Part of the `@okfit/*` kit, in early development against a single pinned Effect v4 prerelease.
6
6
 
@@ -23,7 +23,9 @@ const program = Effect.gen(function* () {
23
23
  });
24
24
  ```
25
25
 
26
- `Bundle.load` needs `FileSystem` and `Path`; `OkfitConfig.read` needs `FileSystem`. Loading never fails on content: bad files become `Diagnostic`s. `Graph.fromBundle` treats a path-valued field or link whose target, resolved from its concept's directory, lands outside the bundle root as an external reference: no graph node and no `broken-links` diagnostic, exactly like a URL. `OkfitConfig` decodes the spec 4.2 TOML shape; unknown top-level keys are kept in `extensions` and reported by `Validate.lint` as `config-unknown-key`. `lifecycle.default_stale_after` accepts `90d`, `12h`, `2w`, or `"90 days"`. `OkfitConfig.merge` deep-merges tables; arrays and scalars in `override` replace wholesale. Apply `DEFAULTS < profile < file` yourself. `OkfitConfigFile` is the service tag; the CLI provides its layer. `okfitConfigDocumentFields` is `okfitConfigFields` minus `extensions` (wire bookkeeping no human writes), with an open rest so unknown top-level keys stay permitted while every declared table stays closed; it is the single source `@okfit/engine`'s `lib/configs/schemastore.config.ts` builds the published JSON Schema (`schemas/1.0/config.json`) from via `effected schema`, and carries no annotations of its own beyond what each field already declares in `OkfitConfig.ts`. The document's `HostedSchema` identity (`okfitConfigSchemaHost`, the same `$id` `okfit init` stamps into a fresh config's `#:schema` directive) lives in `@okfit/engine`, not here — core stays free of a runtime `@effected/schemastore` dependency. The `[lint]` table's seventeen keys include `generated_at_drift` (default `"warn"`), which fires when a committed concept's `generated.at` no longer matches the instant its body was last changed AND is not otherwise authoritative (issue #19: a stamp recorded during the unchanged-body run survives a squash/rebase merge) — computed by `okfit sync`/`okfit validate`, never by core itself.
26
+ `Derive.trustTier` follows OKF 0.3 §5.3 and §7: only current verification events count (`at` equal to or later than `generated.at`, or any event when `generated` or `generated.at` is absent), and only a `human:` verifier gives `human-reviewed`; `team:` and other schemes give `machine-confirmed`. This holds for every bundle whatever `okf_version` it declares. `Derive.isCurrent` and `Derive.currentVerifications` expose the rule, and the `verified-before-change` lint (default `warn`) reports a concept that has a `generated.at` and whose tier dropped because its verification predates it (draft, deprecated and unknown-status concepts are exempt).
27
+
28
+ `Bundle.load` needs `FileSystem` and `Path`; `OkfitConfig.read` needs `FileSystem`. Loading never fails on content: bad files become `Diagnostic`s. `Graph.fromBundle` treats a path-valued field or link whose target, resolved from its concept's directory, lands outside the bundle root as an external reference: no graph node and no `broken-links` diagnostic, exactly like a URL. `OkfitConfig` decodes the spec 4.2 TOML shape; unknown top-level keys are kept in `extensions` and reported by `Validate.lint` as `config-unknown-key`. `[bundle] non_concepts` globs must compile, and a `[` or `{` that never closes is rejected at decode (to match the character write '\[' in single quotes or "\\[" in double quotes). `lifecycle.default_stale_after` accepts `90d`, `12h`, `2w`, or `"90 days"`. `OkfitConfig.merge` deep-merges tables; arrays and scalars in `override` replace wholesale. Apply `DEFAULTS < profile < file` yourself. `OkfitConfigFile` is the service tag; the CLI provides its layer. `okfitConfigDocumentFields` is `okfitConfigFields` minus `extensions` (wire bookkeeping no human writes), with an open rest so unknown top-level keys stay permitted while every declared table stays closed; it is the single source `@okfit/engine`'s `lib/configs/schemastore.config.ts` builds the published JSON Schema (`schemas/1.0/config.json`) from via `effected schema`, and carries no annotations of its own beyond what each field already declares in `OkfitConfig.ts`. The document's `HostedSchema` identity (`okfitConfigSchemaHost`, the same `$id` `okfit init` stamps into a fresh config's `#:schema` directive) lives in `@okfit/engine`, not here — core stays free of a runtime `@effected/schemastore` dependency. The `[lint]` table's forty-four keys include `generated_at_drift` (default `"warn"`), which fires when a committed concept's `generated.at` no longer matches the instant its body was last changed AND is not otherwise authoritative (issue #19: a stamp recorded during the unchanged-body run survives a squash/rebase merge) — computed by `okfit sync`/`okfit validate`, never by core itself.
27
29
 
28
30
  ## License
29
31