@okfit/core 0.3.0 → 0.4.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.
package/Bundle.js CHANGED
@@ -226,7 +226,7 @@ var Bundle = class {
226
226
  maxDepth,
227
227
  prune: new Set(options.prune ?? DEFAULT_PRUNE)
228
228
  }).pipe(Effect.mapError(toLoadError));
229
- const diagnostics = walked.unreadable.map((dir) => diagnostic(dir, "walk-unreadable", "warning", `directory "${dir}" could not be read; its files are not part of the bundle`));
229
+ const diagnostics = walked.unreadable.map(({ path: dir, reason }) => diagnostic(dir, "walk-unreadable", "warning", `directory "${dir}" could not be read (${reason}); its files are not part of the bundle`));
230
230
  const concepts = /* @__PURE__ */ new Map();
231
231
  const indexes = /* @__PURE__ */ new Map();
232
232
  const logs = /* @__PURE__ */ new Map();
package/Diagnostic.js CHANGED
@@ -30,6 +30,7 @@ const LintCode = Schema.Literals([
30
30
  "family-invalid",
31
31
  "computation-runtime-missing",
32
32
  "footnote-source-unknown",
33
+ "footnote-undefined",
33
34
  "log-frontmatter",
34
35
  "actor-prefix-unknown",
35
36
  "legacy-timestamp",
package/OkfitConfig.js CHANGED
@@ -73,7 +73,7 @@ const StaleAfterDuration = Schema.annotateEncoded({
73
73
  "12h"
74
74
  ]
75
75
  })(Schema.String.pipe(Schema.check(Schema.isPattern(STALE_AFTER_PATTERN_RE, { message: "expected \"<n>h\", \"<n>d\", \"<n>w\" or \"<n> <unit>\"" })), Schema.decodeTo(Schema.Duration, {
76
- decode: SchemaGetter.transformOrFail((input, options) => Option.match(parseStaleAfter(input), {
76
+ decode: SchemaGetter.transformEffect((input, options) => Option.match(parseStaleAfter(input), {
77
77
  onNone: () => Effect.fail(new SchemaIssue.InvalidValue({ message: `expected "<n>h", "<n>d", "<n>w" or "<n> <unit>", got ${JSON.stringify(input)}` }, input, options)),
78
78
  onSome: Effect.succeed
79
79
  })),
@@ -104,7 +104,7 @@ const TypeDeclaration = Schema.Struct({
104
104
  guidance: Schema.optionalKey(Schema.String.annotate({ description: "Longer guidance shown to an authoring agent or human writing a concept of this type." })),
105
105
  required: Schema.optionalKey(Schema.Array(Schema.String).annotate({ description: "Frontmatter keys a concept of this type must carry, beyond `concepts.required`." })),
106
106
  require_verified: Schema.optionalKey(Schema.Boolean.annotate({
107
- description: "Whether a concept of this type must carry a `verified` entry to satisfy lint `require-verified-unmet`.",
107
+ description: "Whether a concept of this type must carry a `verified` entry to satisfy lint `require-verified-unmet`; a concept with status draft is exempt.",
108
108
  default: false
109
109
  })),
110
110
  fields: Schema.optionalKey(Schema.Record(Schema.String, FieldDeclaration).annotate({ description: "Extension fields this type's frontmatter may declare." }))
@@ -152,7 +152,7 @@ const LintTable = Schema.Struct({
152
152
  })),
153
153
  require_verified_unmet: Schema.optionalKey(LintLevel.annotate({
154
154
  title: "require-verified-unmet",
155
- description: "A concept whose type sets require_verified = true carries no verified entry. Default \"error\".",
155
+ description: "A concept whose type sets require_verified = true carries no verified entry and is not a draft. Default \"error\".",
156
156
  default: "error"
157
157
  })),
158
158
  family_invalid: Schema.optionalKey(LintLevel.annotate({
@@ -170,6 +170,11 @@ const LintTable = Schema.Struct({
170
170
  description: "A footnote's source does not resolve. Default \"warn\".",
171
171
  default: "warn"
172
172
  })),
173
+ footnote_undefined: Schema.optionalKey(LintLevel.annotate({
174
+ title: "footnote-undefined",
175
+ description: "A footnote reference has no matching definition line in the body. Default \"warn\".",
176
+ default: "warn"
177
+ })),
173
178
  log_frontmatter: Schema.optionalKey(LintLevel.annotate({
174
179
  title: "log-frontmatter",
175
180
  description: "log.md carries frontmatter, which the spec reserves against. Default \"warn\".",
@@ -368,6 +373,7 @@ const LINT_KEY = {
368
373
  "family-invalid": "family_invalid",
369
374
  "computation-runtime-missing": "computation_runtime_missing",
370
375
  "footnote-source-unknown": "footnote_source_unknown",
376
+ "footnote-undefined": "footnote_undefined",
371
377
  "log-frontmatter": "log_frontmatter",
372
378
  "actor-prefix-unknown": "actor_prefix_unknown",
373
379
  "legacy-timestamp": "legacy_timestamp",
@@ -386,6 +392,7 @@ const DEFAULT_LINT = {
386
392
  family_invalid: "error",
387
393
  computation_runtime_missing: "error",
388
394
  footnote_source_unknown: "warn",
395
+ footnote_undefined: "warn",
389
396
  log_frontmatter: "warn",
390
397
  actor_prefix_unknown: "info",
391
398
  legacy_timestamp: "info",
package/README.md CHANGED
@@ -23,7 +23,7 @@ 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 `lib/scripts/generate-schema.ts` builds the published JSON Schema (`schemas/config/okfit-1.0.0.json`) from, and carries no annotations of its own beyond what each field already declares in `OkfitConfig.ts`. The `[lint]` table's sixteen 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
+ `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 `lib/scripts/generate-schema.ts` builds the published JSON Schema (`schemas/config/okfit-1.0.0.json`) from, and carries no annotations of its own beyond what each field already declares in `OkfitConfig.ts`. 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.
27
27
 
28
28
  ## License
29
29
 
package/index.d.ts CHANGED
@@ -206,11 +206,11 @@ export declare const ConformanceCode: Schema.Literals<readonly ["frontmatter-mis
206
206
  /** @public */
207
207
  export type ConformanceCode = typeof ConformanceCode.Type;
208
208
  /** Severity from `OkfitConfig` (D-34). @public */
209
- export declare const LintCode: Schema.Literals<readonly ["broken-links", "missing-index", "unknown-type", "required-key-missing", "field-value-unknown", "require-verified-unmet", "family-invalid", "computation-runtime-missing", "footnote-source-unknown", "log-frontmatter", "actor-prefix-unknown", "legacy-timestamp", "config-unknown-key", "stale", "walk-unreadable", "generated-at-drift"]>;
209
+ export declare const LintCode: Schema.Literals<readonly ["broken-links", "missing-index", "unknown-type", "required-key-missing", "field-value-unknown", "require-verified-unmet", "family-invalid", "computation-runtime-missing", "footnote-source-unknown", "footnote-undefined", "log-frontmatter", "actor-prefix-unknown", "legacy-timestamp", "config-unknown-key", "stale", "walk-unreadable", "generated-at-drift"]>;
210
210
  /** @public */
211
211
  export type LintCode = typeof LintCode.Type;
212
212
  /** @public */
213
- export declare const DiagnosticCode: Schema.Union<readonly [Schema.Literals<readonly ["frontmatter-missing", "frontmatter-unclosed", "frontmatter-unparseable", "type-missing", "index-frontmatter", "index-malformed", "log-heading-invalid", "log-malformed"]>, Schema.Literals<readonly ["broken-links", "missing-index", "unknown-type", "required-key-missing", "field-value-unknown", "require-verified-unmet", "family-invalid", "computation-runtime-missing", "footnote-source-unknown", "log-frontmatter", "actor-prefix-unknown", "legacy-timestamp", "config-unknown-key", "stale", "walk-unreadable", "generated-at-drift"]>]>;
213
+ export declare const DiagnosticCode: Schema.Union<readonly [Schema.Literals<readonly ["frontmatter-missing", "frontmatter-unclosed", "frontmatter-unparseable", "type-missing", "index-frontmatter", "index-malformed", "log-heading-invalid", "log-malformed"]>, Schema.Literals<readonly ["broken-links", "missing-index", "unknown-type", "required-key-missing", "field-value-unknown", "require-verified-unmet", "family-invalid", "computation-runtime-missing", "footnote-source-unknown", "footnote-undefined", "log-frontmatter", "actor-prefix-unknown", "legacy-timestamp", "config-unknown-key", "stale", "walk-unreadable", "generated-at-drift"]>]>;
214
214
  /** @public */
215
215
  export type DiagnosticCode = typeof DiagnosticCode.Type;
216
216
  declare const DiagnosticRange_base: Schema.Class<DiagnosticRange, Schema.Struct<{
@@ -230,7 +230,7 @@ export declare class DiagnosticRange extends DiagnosticRange_base {
230
230
  declare const Diagnostic_base: Schema.Class<Diagnostic, Schema.Struct<{
231
231
  readonly file: Schema.String;
232
232
  readonly range: Schema.optionalKey<typeof DiagnosticRange>;
233
- readonly code: Schema.Union<readonly [Schema.Literals<readonly ["frontmatter-missing", "frontmatter-unclosed", "frontmatter-unparseable", "type-missing", "index-frontmatter", "index-malformed", "log-heading-invalid", "log-malformed"]>, Schema.Literals<readonly ["broken-links", "missing-index", "unknown-type", "required-key-missing", "field-value-unknown", "require-verified-unmet", "family-invalid", "computation-runtime-missing", "footnote-source-unknown", "log-frontmatter", "actor-prefix-unknown", "legacy-timestamp", "config-unknown-key", "stale", "walk-unreadable", "generated-at-drift"]>]>;
233
+ readonly code: Schema.Union<readonly [Schema.Literals<readonly ["frontmatter-missing", "frontmatter-unclosed", "frontmatter-unparseable", "type-missing", "index-frontmatter", "index-malformed", "log-heading-invalid", "log-malformed"]>, Schema.Literals<readonly ["broken-links", "missing-index", "unknown-type", "required-key-missing", "field-value-unknown", "require-verified-unmet", "family-invalid", "computation-runtime-missing", "footnote-source-unknown", "footnote-undefined", "log-frontmatter", "actor-prefix-unknown", "legacy-timestamp", "config-unknown-key", "stale", "walk-unreadable", "generated-at-drift"]>]>;
234
234
  readonly severity: Schema.Literals<readonly ["error", "warning", "info"]>;
235
235
  readonly message: Schema.String;
236
236
  }>, {}>;
@@ -639,6 +639,7 @@ export declare const LintTable: Schema.Struct<{
639
639
  readonly family_invalid: Schema.optionalKey<Schema.Literals<readonly ["off", "info", "warn", "error"]>>;
640
640
  readonly computation_runtime_missing: Schema.optionalKey<Schema.Literals<readonly ["off", "info", "warn", "error"]>>;
641
641
  readonly footnote_source_unknown: Schema.optionalKey<Schema.Literals<readonly ["off", "info", "warn", "error"]>>;
642
+ readonly footnote_undefined: Schema.optionalKey<Schema.Literals<readonly ["off", "info", "warn", "error"]>>;
642
643
  readonly log_frontmatter: Schema.optionalKey<Schema.Literals<readonly ["off", "info", "warn", "error"]>>;
643
644
  readonly actor_prefix_unknown: Schema.optionalKey<Schema.Literals<readonly ["off", "info", "warn", "error"]>>;
644
645
  readonly legacy_timestamp: Schema.optionalKey<Schema.Literals<readonly ["off", "info", "warn", "error"]>>;
@@ -685,6 +686,7 @@ declare const okfitConfigFields: Schema.Struct<{
685
686
  readonly family_invalid: Schema.optionalKey<Schema.Literals<readonly ["off", "info", "warn", "error"]>>;
686
687
  readonly computation_runtime_missing: Schema.optionalKey<Schema.Literals<readonly ["off", "info", "warn", "error"]>>;
687
688
  readonly footnote_source_unknown: Schema.optionalKey<Schema.Literals<readonly ["off", "info", "warn", "error"]>>;
689
+ readonly footnote_undefined: Schema.optionalKey<Schema.Literals<readonly ["off", "info", "warn", "error"]>>;
688
690
  readonly log_frontmatter: Schema.optionalKey<Schema.Literals<readonly ["off", "info", "warn", "error"]>>;
689
691
  readonly actor_prefix_unknown: Schema.optionalKey<Schema.Literals<readonly ["off", "info", "warn", "error"]>>;
690
692
  readonly legacy_timestamp: Schema.optionalKey<Schema.Literals<readonly ["off", "info", "warn", "error"]>>;
@@ -749,6 +751,7 @@ export declare const okfitConfigDocumentFields: Schema.StructWithRest<Schema.Str
749
751
  readonly family_invalid: Schema.optionalKey<Schema.Literals<readonly ["off", "info", "warn", "error"]>>;
750
752
  readonly computation_runtime_missing: Schema.optionalKey<Schema.Literals<readonly ["off", "info", "warn", "error"]>>;
751
753
  readonly footnote_source_unknown: Schema.optionalKey<Schema.Literals<readonly ["off", "info", "warn", "error"]>>;
754
+ readonly footnote_undefined: Schema.optionalKey<Schema.Literals<readonly ["off", "info", "warn", "error"]>>;
752
755
  readonly log_frontmatter: Schema.optionalKey<Schema.Literals<readonly ["off", "info", "warn", "error"]>>;
753
756
  readonly actor_prefix_unknown: Schema.optionalKey<Schema.Literals<readonly ["off", "info", "warn", "error"]>>;
754
757
  readonly legacy_timestamp: Schema.optionalKey<Schema.Literals<readonly ["off", "info", "warn", "error"]>>;
@@ -833,6 +836,7 @@ declare const OkfitConfigFile_base: import("effect/Context").ServiceClass<OkfitC
833
836
  readonly family_invalid?: "error" | "info" | "off" | "warn";
834
837
  readonly computation_runtime_missing?: "error" | "info" | "off" | "warn";
835
838
  readonly footnote_source_unknown?: "error" | "info" | "off" | "warn";
839
+ readonly footnote_undefined?: "error" | "info" | "off" | "warn";
836
840
  readonly log_frontmatter?: "error" | "info" | "off" | "warn";
837
841
  readonly actor_prefix_unknown?: "error" | "info" | "off" | "warn";
838
842
  readonly legacy_timestamp?: "error" | "info" | "off" | "warn";
@@ -5,6 +5,8 @@ import { DateTime } from "effect";
5
5
 
6
6
  //#region src/internal/lintRules.ts
7
7
  const FOOTNOTE_RE = /\[\^([^\]\s]+)\]/g;
8
+ /** A footnote definition: the label at a line start, followed by a colon. */
9
+ const FOOTNOTE_DEFINITION_RE = /^\[\^([^\]\s]+)\]:/gm;
8
10
  const frontmatterRange = (concept) => {
9
11
  const node = concept.document.frontmatter;
10
12
  if (node === void 0) return;
@@ -42,7 +44,7 @@ const fieldValueUnknown = perConcept("field-value-unknown", (concept, context) =
42
44
  }
43
45
  return out;
44
46
  });
45
- const requireVerifiedUnmet = perConcept("require-verified-unmet", (concept, context) => context.config.types?.[concept.frontmatter.type]?.require_verified === true && (concept.frontmatter.verified ?? []).length === 0 ? [`Type "${concept.frontmatter.type}" requires a verified entry`] : []);
47
+ const requireVerifiedUnmet = perConcept("require-verified-unmet", (concept, context) => context.config.types?.[concept.frontmatter.type]?.require_verified === true && concept.frontmatter.status !== "draft" && (concept.frontmatter.verified ?? []).length === 0 ? [`Type "${concept.frontmatter.type}" requires a verified entry`] : []);
46
48
  const actorPrefixUnknown = perConcept("actor-prefix-unknown", (concept) => {
47
49
  return [concept.frontmatter.generated?.by, ...(concept.frontmatter.verified ?? []).map((v) => v.by)].filter((by) => by !== void 0 && Actor.form(by) === "other").map((by) => `Actor "${by}" uses an unknown prefix; expected human:<id>, process:<id>, or <producer>/<version>`);
48
50
  });
@@ -65,6 +67,24 @@ const footnoteSourceUnknown = rule("footnote-source-unknown", (context, severity
65
67
  }
66
68
  return out;
67
69
  });
70
+ const footnoteUndefined = rule("footnote-undefined", (context, severity) => {
71
+ const out = [];
72
+ for (const concept of context.bundle.concepts.values()) {
73
+ const source = concept.document.source;
74
+ const start = concept.document.frontmatter?.position.end.offset ?? 0;
75
+ const body = source.slice(start);
76
+ const defined = new Set([...body.matchAll(FOOTNOTE_DEFINITION_RE)].flatMap((m) => m[1] === void 0 ? [] : [m[1]]));
77
+ const seen = /* @__PURE__ */ new Set();
78
+ for (const match of body.matchAll(FOOTNOTE_RE)) {
79
+ const label = match[1];
80
+ if (label === void 0 || defined.has(label) || seen.has(label)) continue;
81
+ seen.add(label);
82
+ const range = DiagnosticRange.fromOffset(source, start + match.index, match[0].length);
83
+ out.push(diagnostic(concept.path, "footnote-undefined", severity, `Footnote "${label}" is referenced but has no [^${label}]: definition`, range));
84
+ }
85
+ }
86
+ return out;
87
+ });
68
88
  const brokenLinks = rule("broken-links", (context, severity) => {
69
89
  const pathOf = new Map([...context.bundle.concepts.values()].map((concept) => [concept.id, concept.path]));
70
90
  return context.graph.dangling().map((link) => {
@@ -85,10 +105,11 @@ const LINT_RULES = [
85
105
  requireVerifiedUnmet,
86
106
  actorPrefixUnknown,
87
107
  footnoteSourceUnknown,
108
+ footnoteUndefined,
88
109
  brokenLinks,
89
110
  missingIndex,
90
111
  stale
91
112
  ];
92
113
 
93
114
  //#endregion
94
- export { LINT_RULES, actorPrefixUnknown, brokenLinks, configUnknownKey, fieldValueUnknown, footnoteSourceUnknown, missingIndex, requireVerifiedUnmet, requiredKeyMissing, stale, unknownType };
115
+ export { LINT_RULES, actorPrefixUnknown, brokenLinks, configUnknownKey, fieldValueUnknown, footnoteSourceUnknown, footnoteUndefined, missingIndex, requireVerifiedUnmet, requiredKeyMissing, stale, unknownType };
package/internal/walk.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Effect, FileSystem } from "effect";
1
+ import { Effect } from "effect";
2
2
  import { descend } from "@effected/walker";
3
3
  import { GlobPattern, GlobPatternOptions } from "@effected/glob";
4
4
 
@@ -26,15 +26,12 @@ const walk = (options) => Effect.gen(function* () {
26
26
  prune: [...options.prune],
27
27
  onUnreadable: "record"
28
28
  });
29
- if (result.unreadable.includes("")) {
30
- yield* (yield* FileSystem.FileSystem).readDirectory(options.root);
31
- const unreadable = result.unreadable.filter((entry) => entry !== "").sort();
32
- return {
33
- files: result.matches,
34
- unreadable
35
- };
36
- }
37
- const unreadable = [...result.unreadable].sort();
29
+ const root = result.unreadable.find((entry) => entry.path === "");
30
+ if (root !== void 0) return yield* Effect.fail(root.cause);
31
+ const unreadable = result.unreadable.map((entry) => ({
32
+ path: entry.path,
33
+ reason: entry.cause.reason._tag
34
+ })).sort((a, b) => a.path < b.path ? -1 : a.path > b.path ? 1 : 0);
38
35
  return {
39
36
  files: result.matches,
40
37
  unreadable
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@okfit/core",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "private": false,
5
5
  "description": "Spec-level Open Knowledge Format (OKF) v0.2 schemas, bundle loading, graph, derivation, and validation for Effect.",
6
6
  "keywords": [
@@ -37,14 +37,14 @@
37
37
  "./package.json": "./package.json"
38
38
  },
39
39
  "peerDependencies": {
40
- "@effected/config-file": "^0.7.0",
41
- "@effected/glob": "^0.5.0",
42
- "@effected/jsonc": "^0.9.0",
43
- "@effected/markdown": "^0.9.0",
44
- "@effected/toml": "^0.6.0",
45
- "@effected/walker": "^0.7.0",
46
- "@effected/yaml": "^0.14.0",
47
- "effect": "4.0.0-rc.112"
40
+ "@effected/config-file": "^0.9.0",
41
+ "@effected/glob": "^0.6.0",
42
+ "@effected/jsonc": "^0.11.0",
43
+ "@effected/markdown": "^0.10.0",
44
+ "@effected/toml": "^0.7.0",
45
+ "@effected/walker": "^0.9.0",
46
+ "@effected/yaml": "^0.15.0",
47
+ "effect": "4.0.0-rc.115"
48
48
  },
49
49
  "engines": {
50
50
  "node": ">=24.11.0"
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.59.0"
8
+ "packageVersion": "7.59.1"
9
9
  }
10
10
  ]
11
11
  }