@okfit/core 0.12.1 → 0.13.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/README.md +1 -1
- package/internal/lintRules.js +3 -38
- package/package.json +10 -10
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 `@okfit/engine`'s `lib/configs/schemastore.config.ts` builds the published JSON Schema (`schemas/1.0/config.json`) from via
|
|
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.
|
|
27
27
|
|
|
28
28
|
## License
|
|
29
29
|
|
package/internal/lintRules.js
CHANGED
|
@@ -3,6 +3,7 @@ import { Derive } from "../Derive.js";
|
|
|
3
3
|
import { Diagnostic, DiagnosticRange } from "../Diagnostic.js";
|
|
4
4
|
import { frontmatterPathRange } from "./frontmatter.js";
|
|
5
5
|
import { DateTime, Option } from "effect";
|
|
6
|
+
import { EditDistance } from "@effected/source";
|
|
6
7
|
|
|
7
8
|
// src/internal/lintRules.ts
|
|
8
9
|
const FOOTNOTE_RE = /\[\^([^\]\s]+)\]/g;
|
|
@@ -164,44 +165,8 @@ const footnoteUndefined = rule("footnote-undefined", (context, severity) => {
|
|
|
164
165
|
}
|
|
165
166
|
return out;
|
|
166
167
|
});
|
|
167
|
-
/** GitHub-style heading slug: lowercase, punctuation dropped, spaces to hyphens, duplicates suffixed `-1`, `-2`, ... */
|
|
168
|
-
const headingSlugs = (concept) => {
|
|
169
|
-
const seen = /* @__PURE__ */ new Map();
|
|
170
|
-
const slugs = [];
|
|
171
|
-
for (const heading of concept.document.headings) {
|
|
172
|
-
const base = heading.text.toLowerCase().replace(/[^\p{L}\p{N}\s-]/gu, "").trim().replace(/\s+/g, "-");
|
|
173
|
-
const count = seen.get(base) ?? 0;
|
|
174
|
-
seen.set(base, count + 1);
|
|
175
|
-
slugs.push(count === 0 ? base : `${base}-${count}`);
|
|
176
|
-
}
|
|
177
|
-
return slugs;
|
|
178
|
-
};
|
|
179
|
-
/** Levenshtein distance (two-row DP). */
|
|
180
|
-
const editDistance = (a, b) => {
|
|
181
|
-
let previous = Array.from({ length: b.length + 1 }, (_, index) => index);
|
|
182
|
-
for (let i = 1; i <= a.length; i++) {
|
|
183
|
-
const current = [i];
|
|
184
|
-
for (let j = 1; j <= b.length; j++) {
|
|
185
|
-
const cost = a[i - 1] === b[j - 1] ? 0 : 1;
|
|
186
|
-
current[j] = Math.min((previous[j] ?? 0) + 1, (current[j - 1] ?? 0) + 1, (previous[j - 1] ?? 0) + cost);
|
|
187
|
-
}
|
|
188
|
-
previous = current;
|
|
189
|
-
}
|
|
190
|
-
return previous[b.length] ?? 0;
|
|
191
|
-
};
|
|
192
168
|
/** The closest slug within max(2, ⌊|fragment| / 3⌋) edits, ties to the earliest heading; else undefined. */
|
|
193
|
-
const nearestSlug = (fragment, slugs) => {
|
|
194
|
-
const limit = Math.max(2, Math.floor(fragment.length / 3));
|
|
195
|
-
let best;
|
|
196
|
-
for (const slug of slugs) {
|
|
197
|
-
const distance = editDistance(fragment, slug);
|
|
198
|
-
if (distance <= limit && (best === void 0 || distance < best.distance)) best = {
|
|
199
|
-
slug,
|
|
200
|
-
distance
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
return best?.slug;
|
|
204
|
-
};
|
|
169
|
+
const nearestSlug = (fragment, slugs) => EditDistance.suggest(fragment, slugs, { maxDistance: Math.max(2, Math.floor(fragment.length / 3)) })[0];
|
|
205
170
|
const candidateHint = (fragment, slugs) => {
|
|
206
171
|
if (slugs.length === 0) return "it has no headings";
|
|
207
172
|
const near = nearestSlug(fragment, slugs);
|
|
@@ -231,7 +196,7 @@ const brokenLinks = rule("broken-links", (context, severity) => {
|
|
|
231
196
|
const slugsOf = (id, target) => {
|
|
232
197
|
const cached = slugCache.get(id);
|
|
233
198
|
if (cached !== void 0) return cached;
|
|
234
|
-
const slugs = headingSlugs
|
|
199
|
+
const slugs = target.document.headingSlugs;
|
|
235
200
|
slugCache.set(id, slugs);
|
|
236
201
|
return slugs;
|
|
237
202
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@okfit/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.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,15 +37,15 @@
|
|
|
37
37
|
"./package.json": "./package.json"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
|
-
"@effected/config-file": "^0.
|
|
41
|
-
"@effected/glob": "^0.
|
|
42
|
-
"@effected/jsonc": "^0.
|
|
43
|
-
"@effected/markdown": "^0.
|
|
44
|
-
"@effected/schemastore": "^0.
|
|
45
|
-
"@effected/source": "^0.
|
|
46
|
-
"@effected/toml": "^0.19.
|
|
47
|
-
"@effected/walker": "^0.25.
|
|
48
|
-
"@effected/yaml": "^0.
|
|
40
|
+
"@effected/config-file": "^0.25.0",
|
|
41
|
+
"@effected/glob": "^0.19.0",
|
|
42
|
+
"@effected/jsonc": "^0.24.0",
|
|
43
|
+
"@effected/markdown": "^0.27.0",
|
|
44
|
+
"@effected/schemastore": "^0.30.0",
|
|
45
|
+
"@effected/source": "^0.4.0",
|
|
46
|
+
"@effected/toml": "^0.19.1",
|
|
47
|
+
"@effected/walker": "^0.25.1",
|
|
48
|
+
"@effected/yaml": "^0.29.0",
|
|
49
49
|
"effect": "~4.1.2"
|
|
50
50
|
},
|
|
51
51
|
"engines": {
|