@okfit/core 0.15.0 → 0.17.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 +29 -5
- package/Concept.js +10 -0
- package/ConfinedRead.js +113 -0
- package/Derive.js +3 -3
- package/Diagnostic.js +23 -2
- package/GeneratedAtFuture.js +9 -1
- package/IndexDocument.js +3 -1
- package/LintTable.js +292 -0
- package/LogDocument.js +3 -1
- package/OkfVersion.js +4 -1
- package/OkfitConfig.js +215 -250
- package/README.md +1 -1
- package/Reference.js +65 -0
- package/RepoIdentity.js +46 -0
- package/index.d.ts +337 -50
- package/index.js +7 -3
- package/internal/conceptDecode.js +36 -21
- package/internal/frontmatter.js +2 -2
- package/internal/linkScan.js +57 -0
- package/internal/lintRules.js +35 -14
- package/internal/position.js +2 -2
- package/internal/reserved.js +21 -4
- package/internal/walk.js +1 -0
- package/internal/yamlPathSpan.js +82 -4
- package/package.json +9 -7
- package/tsdoc-metadata.json +1 -1
package/Bundle.js
CHANGED
|
@@ -4,10 +4,12 @@ import { YamlParseError } from "@effected/yaml";
|
|
|
4
4
|
import { Effect, FileSystem, Option, Path, Result, Schema } from "effect";
|
|
5
5
|
import { Concept } from "./Concept.js";
|
|
6
6
|
import { ConceptId } from "./ConceptId.js";
|
|
7
|
+
import { readConfinedString } from "./ConfinedRead.js";
|
|
7
8
|
import { Diagnostic, DiagnosticRange } from "./Diagnostic.js";
|
|
8
9
|
import { IndexDocument } from "./IndexDocument.js";
|
|
9
10
|
import { detectFence } from "./internal/fence.js";
|
|
10
11
|
import { decodeConcept } from "./internal/frontmatter.js";
|
|
12
|
+
import { COULD_NOT_RESOLVE, RESOLVES_OUTSIDE, scanLinks } from "./internal/linkScan.js";
|
|
11
13
|
import { toFileOffset } from "./internal/position.js";
|
|
12
14
|
import { OPTIONS, parseIndex, parseLog } from "./internal/reserved.js";
|
|
13
15
|
import { DEFAULT_PRUNE, walk } from "./internal/walk.js";
|
|
@@ -238,6 +240,15 @@ var Bundle = class Bundle {
|
|
|
238
240
|
* fails: every bad file becomes a diagnostic and loading continues (spec 8). A walk
|
|
239
241
|
* that descends past `options.maxDepth` fails typed with `BundleDepthExceededError`
|
|
240
242
|
* (W-1) rather than being silently truncated.
|
|
243
|
+
*
|
|
244
|
+
* A symbolic link is never followed out of the bundle (OKF 0.3 section 3.2 rule 5). A file link that leaves
|
|
245
|
+
* it, a directory link that leaves it (nothing under it is read), and a link of either kind whose resolution
|
|
246
|
+
* fails (dangling, a loop, an unreadable target) each record a `symlink-escape` warning at their own path
|
|
247
|
+
* (a pruned name, `node_modules` by default, is silent for a file link and a directory link alike and the link is never read; hidden names are checked only under `includeHidden`); a directory link that stays inside is never walked and
|
|
248
|
+
* records nothing. Each Markdown file is read confined (`readConfinedString`): a file that becomes a link out of
|
|
249
|
+
* the bundle between the link check and the read is refused as `symlink-escape`, and one that changed under the
|
|
250
|
+
* read (`changed`) is recorded `read-changed` ("try again") and left out of that load. A race through a directory above
|
|
251
|
+
* the file can still win (spencerbeggs/okfit#524).
|
|
241
252
|
*/
|
|
242
253
|
static load = Effect.fn("Bundle.load")(function* (options) {
|
|
243
254
|
const fs = yield* FileSystem.FileSystem;
|
|
@@ -266,11 +277,12 @@ var Bundle = class Bundle {
|
|
|
266
277
|
cause: error
|
|
267
278
|
});
|
|
268
279
|
};
|
|
280
|
+
const prune = new Set(options.prune ?? DEFAULT_PRUNE);
|
|
269
281
|
const walked = yield* walk({
|
|
270
282
|
root,
|
|
271
283
|
includeHidden: options.includeHidden ?? false,
|
|
272
284
|
maxDepth,
|
|
273
|
-
prune
|
|
285
|
+
prune
|
|
274
286
|
}).pipe(Effect.mapError(toLoadError));
|
|
275
287
|
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`));
|
|
276
288
|
const files = [];
|
|
@@ -280,30 +292,42 @@ var Bundle = class Bundle {
|
|
|
280
292
|
path: file,
|
|
281
293
|
cause
|
|
282
294
|
})))).type === "SymbolicLink") {
|
|
295
|
+
if (prune.has(file.slice(file.lastIndexOf("/") + 1))) continue;
|
|
283
296
|
const refused = yield* confineReal(root, path.join(root, file)).pipe(Effect.match({
|
|
284
297
|
onFailure: (error) => error,
|
|
285
298
|
onSuccess: () => void 0
|
|
286
299
|
}));
|
|
287
300
|
if (refused !== void 0) {
|
|
288
|
-
const why = refused.reason === "outside" ?
|
|
301
|
+
const why = refused.reason === "outside" ? RESOLVES_OUTSIDE : COULD_NOT_RESOLVE;
|
|
289
302
|
diagnostics.push(diagnostic(file, "symlink-escape", "warning", `symbolic link ${why}; it is not read and not part of the bundle`));
|
|
290
303
|
continue;
|
|
291
304
|
}
|
|
292
305
|
}
|
|
293
306
|
files.push(file);
|
|
294
307
|
}
|
|
308
|
+
const links = yield* scanLinks(root, walked.links, {
|
|
309
|
+
includeHidden: options.includeHidden ?? false,
|
|
310
|
+
prune
|
|
311
|
+
});
|
|
312
|
+
for (const link of links) diagnostics.push(diagnostic(link.file, "symlink-escape", "warning", link.message));
|
|
295
313
|
const concepts = /* @__PURE__ */ new Map();
|
|
296
314
|
const indexes = /* @__PURE__ */ new Map();
|
|
297
315
|
const logs = /* @__PURE__ */ new Map();
|
|
298
316
|
const directories = /* @__PURE__ */ new Set();
|
|
317
|
+
const refusedAtRead = /* @__PURE__ */ new Set();
|
|
299
318
|
for (const file of files) {
|
|
300
319
|
if (!file.endsWith(".md")) continue;
|
|
301
|
-
const
|
|
320
|
+
const read = yield* readConfinedString(root, path.join(root, file)).pipe(Effect.map((text) => ({ text })), Effect.catchTag("ConfinementError", (error) => Effect.succeed({ refused: error.reason })), Effect.mapError((cause) => new BundleReadError({
|
|
302
321
|
root,
|
|
303
322
|
path: file,
|
|
304
323
|
cause
|
|
305
324
|
})));
|
|
306
|
-
|
|
325
|
+
if ("refused" in read) {
|
|
326
|
+
refusedAtRead.add(file);
|
|
327
|
+
diagnostics.push(read.refused === "changed" ? diagnostic(file, "read-changed", "warning", `file "${file}" changed while it was read; try again. It is not part of this load`) : diagnostic(file, "symlink-escape", "warning", `symbolic link ${read.refused === "outside" ? RESOLVES_OUTSIDE : COULD_NOT_RESOLVE}; it is not read and not part of the bundle`));
|
|
328
|
+
continue;
|
|
329
|
+
}
|
|
330
|
+
const outcome = yield* loadMarkdown(file, read.text);
|
|
307
331
|
diagnostics.push(...outcome.diagnostics);
|
|
308
332
|
if (outcome.concept !== void 0) {
|
|
309
333
|
concepts.set(outcome.concept.id, outcome.concept);
|
|
@@ -314,7 +338,7 @@ var Bundle = class Bundle {
|
|
|
314
338
|
}
|
|
315
339
|
const bundle = LoadedBundle.make({
|
|
316
340
|
root,
|
|
317
|
-
files,
|
|
341
|
+
files: refusedAtRead.size === 0 ? files : files.filter((file) => !refusedAtRead.has(file)),
|
|
318
342
|
directories: [...directories].sort(),
|
|
319
343
|
concepts,
|
|
320
344
|
indexes,
|
package/Concept.js
CHANGED
|
@@ -68,6 +68,16 @@ var Concept = class extends Schema.Class("Concept")({
|
|
|
68
68
|
if (recorded !== void 0) return recorded;
|
|
69
69
|
return Array.isArray(concept.raw[family]) ? [family, position] : [family];
|
|
70
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* OKF 0.3 §11.2 rule 1: `undefined`, `null`, an empty string and an empty list read as absent.
|
|
73
|
+
*
|
|
74
|
+
* @remarks
|
|
75
|
+
* A mapping, `{}` included, is not absent. A family the decoder ignores (a `generated` without a readable
|
|
76
|
+
* `by`) reads as absent through the decoded `Concept`, not through this predicate.
|
|
77
|
+
*/
|
|
78
|
+
static isAbsent(value) {
|
|
79
|
+
return value === void 0 || value === null || value === "" || Array.isArray(value) && value.length === 0;
|
|
80
|
+
}
|
|
71
81
|
};
|
|
72
82
|
|
|
73
83
|
export { ATTESTED_COMPUTATION_TYPE, Concept, EntryPaths };
|
package/ConfinedRead.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { confineReal } from "@effected/walker";
|
|
2
|
+
import { Effect, FileSystem, Option, Schema } from "effect";
|
|
3
|
+
|
|
4
|
+
// src/ConfinedRead.ts
|
|
5
|
+
/**
|
|
6
|
+
* The transient wording every surface uses for a file that changed under a read: the quoted `subject` (a path or
|
|
7
|
+
* a concept file name) followed by `changed while it was read; try again`. One spelling, so the CLI, the MCP server
|
|
8
|
+
* and `ConfinementError` never drift. It is never an escape verdict.
|
|
9
|
+
*
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
const changedWhileRead = (subject) => `"${subject}" changed while it was read; try again`;
|
|
13
|
+
/**
|
|
14
|
+
* A file read was refused (OKF 0.3 section 3.2).
|
|
15
|
+
*
|
|
16
|
+
* `reason` says why: `outside` (a link on the path resolves outside the root), `unresolvable` (a link on the path
|
|
17
|
+
* dangles or cannot be resolved) or `changed` (the path no longer names the file that was opened, or what it names
|
|
18
|
+
* could not be compared: it was swapped, replaced or removed while it was read, so reading again may succeed). Only
|
|
19
|
+
* `outside` and `unresolvable` mean the path leaves the bundle; `changed` is transient and never an escape verdict.
|
|
20
|
+
*
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
var ConfinementError = class extends Schema.TaggedError()("ConfinementError", {
|
|
24
|
+
root: Schema.String,
|
|
25
|
+
/** The path that was read, as it was given. */
|
|
26
|
+
path: Schema.String,
|
|
27
|
+
reason: Schema.Literals([
|
|
28
|
+
"outside",
|
|
29
|
+
"unresolvable",
|
|
30
|
+
"changed"
|
|
31
|
+
])
|
|
32
|
+
}) {
|
|
33
|
+
get message() {
|
|
34
|
+
return this.reason === "outside" ? `"${this.path}" resolves outside the bundle root "${this.root}"` : this.reason === "unresolvable" ? `"${this.path}" could not be resolved, so it cannot be shown to stay inside the bundle root "${this.root}"` : changedWhileRead(this.path);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
const CHUNK = 65536;
|
|
38
|
+
/**
|
|
39
|
+
* Read the file `target` (an absolute path) under `root` confined to it, so a link swapped in after a check is not
|
|
40
|
+
* read: open the file, resolve the path with `confineReal` (every link on it, at the file or at a directory above
|
|
41
|
+
* it), require that the path still exists (`realPath`), then require that the open file is the file the resolved
|
|
42
|
+
* path names (`dev` and `ino` of the open file's `stat` against `lstat` of the real path, which must itself be a
|
|
43
|
+
* file and not a link). The bytes come from the open file, never from a second open of the path.
|
|
44
|
+
*
|
|
45
|
+
* The guarantee is exact about one case: a link at the file itself, swapped in at any moment during the read, is
|
|
46
|
+
* refused. A race through a directory above the file can still win, because the open and the resolution are
|
|
47
|
+
* separate steps on the path (spencerbeggs/okfit#524); there is no retry, which would only widen that window.
|
|
48
|
+
*
|
|
49
|
+
* It fails with {@link ConfinementError} (`outside` or `unresolvable` when a link on the path leaves the root or
|
|
50
|
+
* dangles; `changed` when the path no longer names the file that was opened, or either stat lacks an `ino`), and
|
|
51
|
+
* with the `PlatformError` of the open or the read otherwise. A missing file is that `PlatformError` (`NotFound`)
|
|
52
|
+
* unless a link on its path escapes or dangles. A hard link to a file under the root is a file under the root
|
|
53
|
+
* (OKF 0.3 section 3.2) and is read.
|
|
54
|
+
*
|
|
55
|
+
* Only reads are confined this way. A write stays a check followed by `writeAtomic`.
|
|
56
|
+
*
|
|
57
|
+
* @public
|
|
58
|
+
*/
|
|
59
|
+
const readConfinedBytes = Effect.fn("okfit/ConfinedRead/readConfinedBytes")(function* (root, target) {
|
|
60
|
+
const fs = yield* FileSystem.FileSystem;
|
|
61
|
+
const refuse = (reason) => new ConfinementError({
|
|
62
|
+
root,
|
|
63
|
+
path: target,
|
|
64
|
+
reason
|
|
65
|
+
});
|
|
66
|
+
return yield* Effect.scoped(Effect.gen(function* () {
|
|
67
|
+
const opened = yield* Effect.result(fs.open(target));
|
|
68
|
+
if (opened._tag === "Failure") {
|
|
69
|
+
const refused = yield* confineReal(root, target).pipe(Effect.match({
|
|
70
|
+
onFailure: (error) => error.reason,
|
|
71
|
+
onSuccess: () => void 0
|
|
72
|
+
}));
|
|
73
|
+
if (refused !== void 0) return yield* refuse(refused === "outside" ? "outside" : "unresolvable");
|
|
74
|
+
return yield* Effect.fail(opened.failure);
|
|
75
|
+
}
|
|
76
|
+
const file = opened.success;
|
|
77
|
+
const real = yield* confineReal(root, target).pipe(Effect.mapError((error) => refuse(error.reason === "outside" ? "outside" : "unresolvable")));
|
|
78
|
+
if ((yield* fs.realPath(target).pipe(Effect.mapError(() => refuse("changed")))) !== real) return yield* refuse("changed");
|
|
79
|
+
const held = yield* file.stat;
|
|
80
|
+
const named = yield* fs.lstat(real).pipe(Effect.mapError(() => refuse("changed")));
|
|
81
|
+
if (named.type !== "File") return yield* refuse("changed");
|
|
82
|
+
if (held.dev !== named.dev || !Option.isSome(held.ino) || !Option.isSome(named.ino)) return yield* refuse("changed");
|
|
83
|
+
if (held.ino.value !== named.ino.value) return yield* refuse("changed");
|
|
84
|
+
const chunks = [];
|
|
85
|
+
let length = 0;
|
|
86
|
+
for (;;) {
|
|
87
|
+
const chunk = yield* file.readAlloc(CHUNK);
|
|
88
|
+
if (Option.isNone(chunk)) break;
|
|
89
|
+
chunks.push(chunk.value);
|
|
90
|
+
length += chunk.value.length;
|
|
91
|
+
}
|
|
92
|
+
const bytes = new Uint8Array(length);
|
|
93
|
+
let offset = 0;
|
|
94
|
+
for (const chunk of chunks) {
|
|
95
|
+
bytes.set(chunk, offset);
|
|
96
|
+
offset += chunk.length;
|
|
97
|
+
}
|
|
98
|
+
return bytes;
|
|
99
|
+
}));
|
|
100
|
+
});
|
|
101
|
+
/**
|
|
102
|
+
* {@link readConfinedBytes} decoded as UTF-8. A leading byte-order mark is dropped, as Effect's
|
|
103
|
+
* `FileSystem.readFileString` (a `TextDecoder`) drops it, so the loader reads a BOM file as it always did and a
|
|
104
|
+
* writer gives the BOM back.
|
|
105
|
+
*
|
|
106
|
+
* @public
|
|
107
|
+
*/
|
|
108
|
+
const readConfinedString = Effect.fn("okfit/ConfinedRead/readConfinedString")(function* (root, target) {
|
|
109
|
+
const bytes = yield* readConfinedBytes(root, target);
|
|
110
|
+
return new TextDecoder("utf-8").decode(bytes);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
export { ConfinementError, changedWhileRead, readConfinedBytes, readConfinedString };
|
package/Derive.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PosixPath } from "@effected/walker";
|
|
2
2
|
import { DateTime, Schema } from "effect";
|
|
3
|
-
import {
|
|
3
|
+
import { Concept } from "./Concept.js";
|
|
4
4
|
import { indexDocument, logEntry } from "./internal/templates.js";
|
|
5
5
|
import { tierOf } from "./internal/tier.js";
|
|
6
6
|
|
|
@@ -24,7 +24,7 @@ const Staleness = Schema.Literals([
|
|
|
24
24
|
"malformed"
|
|
25
25
|
]);
|
|
26
26
|
/** `stale_after` is present in `raw` (not `null`, `""` or `[]`) yet did not decode to an instant. */
|
|
27
|
-
const isMalformedStaleAfter = (concept) => concept.stale_after === void 0 && !isAbsent(concept.raw.stale_after);
|
|
27
|
+
const isMalformedStaleAfter = (concept) => concept.stale_after === void 0 && !Concept.isAbsent(concept.raw.stale_after);
|
|
28
28
|
const compare = (a, b) => a < b ? -1 : a > b ? 1 : 0;
|
|
29
29
|
const oneLine = (text) => text.replace(/\s+/g, " ").trim();
|
|
30
30
|
/** The bundle-relative directory of `path`; `""` for a file at the bundle root. */
|
|
@@ -74,7 +74,7 @@ var Derive = class Derive {
|
|
|
74
74
|
/** The `status` value as written, as text for display; `undefined` when absent, `null`, `""` or `[]`. */
|
|
75
75
|
static rawStatus = (concept) => {
|
|
76
76
|
const value = concept.raw.status;
|
|
77
|
-
if (isAbsent(value)) return void 0;
|
|
77
|
+
if (Concept.isAbsent(value)) return void 0;
|
|
78
78
|
return typeof value === "string" ? value : JSON.stringify(value);
|
|
79
79
|
};
|
|
80
80
|
/**
|
package/Diagnostic.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { LineIndex } from "@effected/source";
|
|
2
2
|
import { Option, Schema } from "effect";
|
|
3
|
-
import { frontmatterPathSpan } from "./internal/yamlPathSpan.js";
|
|
3
|
+
import { findFrontmatterKeySpan, frontmatterPathSpan } from "./internal/yamlPathSpan.js";
|
|
4
4
|
|
|
5
5
|
// src/Diagnostic.ts
|
|
6
6
|
/** @public */
|
|
@@ -38,6 +38,7 @@ const LintCode = Schema.Literals([
|
|
|
38
38
|
"config-okf-version-stale",
|
|
39
39
|
"stale",
|
|
40
40
|
"walk-unreadable",
|
|
41
|
+
"read-changed",
|
|
41
42
|
"generated-at-drift",
|
|
42
43
|
"status-missing",
|
|
43
44
|
"source-resource-missing",
|
|
@@ -62,7 +63,14 @@ const LintCode = Schema.Literals([
|
|
|
62
63
|
"symlink-escape",
|
|
63
64
|
"non-concept-unlisted",
|
|
64
65
|
"computation-missing",
|
|
65
|
-
"generated-at-future"
|
|
66
|
+
"generated-at-future",
|
|
67
|
+
"reference-not-mounted",
|
|
68
|
+
"reference-missing",
|
|
69
|
+
"reference-undeclared",
|
|
70
|
+
"reference-local-only",
|
|
71
|
+
"config-misplaced-key",
|
|
72
|
+
"config-local-tracked",
|
|
73
|
+
"bundle-config-invalid"
|
|
66
74
|
]);
|
|
67
75
|
/** @public */
|
|
68
76
|
const DiagnosticCode = Schema.Union([ConformanceCode, LintCode]);
|
|
@@ -105,6 +113,19 @@ var DiagnosticRange = class DiagnosticRange extends Schema.Class("DiagnosticRang
|
|
|
105
113
|
const span = frontmatterPathSpan(document.source, node, path);
|
|
106
114
|
return DiagnosticRange.fromOffset(document.source, span.offset, span.length);
|
|
107
115
|
};
|
|
116
|
+
/**
|
|
117
|
+
* Maps a frontmatter YAML path to the range of its last segment's own key inside `document.source`, or `undefined`
|
|
118
|
+
* when the document has no frontmatter block, the path does not end in a written mapping key, or the key is not
|
|
119
|
+
* there. For a caller that edits a key whose value has no text of its own (a bare `body:` or `body: !!null`, which
|
|
120
|
+
* {@link DiagnosticRange.forFrontmatterPath} reports as the whole block), so it can still find where the value goes.
|
|
121
|
+
*
|
|
122
|
+
* @public
|
|
123
|
+
*/
|
|
124
|
+
static forFrontmatterKey = (document, path) => {
|
|
125
|
+
const node = Option.getOrUndefined(document.frontmatter);
|
|
126
|
+
const span = node === void 0 ? void 0 : findFrontmatterKeySpan(document.source, node, path);
|
|
127
|
+
return span === void 0 ? void 0 : DiagnosticRange.fromOffset(document.source, span.offset, span.length);
|
|
128
|
+
};
|
|
108
129
|
};
|
|
109
130
|
const CONFORMANCE_CODES = new Set(ConformanceCode.literals);
|
|
110
131
|
/**
|
package/GeneratedAtFuture.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DurationWords } from "@effected/kit";
|
|
1
2
|
import { DateTime, Duration, Option } from "effect";
|
|
2
3
|
|
|
3
4
|
// src/GeneratedAtFuture.ts
|
|
@@ -10,6 +11,13 @@ import { DateTime, Duration, Option } from "effect";
|
|
|
10
11
|
*/
|
|
11
12
|
const GENERATED_AT_TOLERANCE = Duration.minutes(5);
|
|
12
13
|
/**
|
|
14
|
+
* {@link GENERATED_AT_TOLERANCE} in words ("5 minutes"), for messages. Derived from the constant with
|
|
15
|
+
* `DurationWords.format`, so changing the tolerance changes every message that names it.
|
|
16
|
+
*
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
const GENERATED_AT_TOLERANCE_TEXT = DurationWords.format(GENERATED_AT_TOLERANCE);
|
|
20
|
+
/**
|
|
13
21
|
* Whether `generatedAt` is more than {@link GENERATED_AT_TOLERANCE} later than `now`. Exactly the tolerance is not
|
|
14
22
|
* future; one millisecond more is.
|
|
15
23
|
*
|
|
@@ -30,4 +38,4 @@ const verificationBlockingRestamp = (verifiedAts, generatedAt, now) => {
|
|
|
30
38
|
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());
|
|
31
39
|
};
|
|
32
40
|
|
|
33
|
-
export { GENERATED_AT_TOLERANCE, generatedAtIsFuture, verificationBlockingRestamp };
|
|
41
|
+
export { GENERATED_AT_TOLERANCE, GENERATED_AT_TOLERANCE_TEXT, generatedAtIsFuture, verificationBlockingRestamp };
|
package/IndexDocument.js
CHANGED
|
@@ -30,7 +30,9 @@ var IndexDocument = class extends Schema.Class("IndexDocument")({
|
|
|
30
30
|
license: Schema.optionalKey(Schema.String),
|
|
31
31
|
metadata: Schema.optionalKey(Schema.Record(Schema.String, Schema.Unknown)),
|
|
32
32
|
frontmatter: Schema.optionalKey(Schema.String),
|
|
33
|
-
sections: Schema.Array(IndexSection)
|
|
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)
|
|
34
36
|
}) {};
|
|
35
37
|
|
|
36
38
|
export { IndexDocument, IndexEntry, IndexSection };
|
package/LintTable.js
ADDED
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { GENERATED_AT_TOLERANCE_TEXT } from "./GeneratedAtFuture.js";
|
|
3
|
+
import { INTEGRITY_KEY, OKFIT_KEY_PREFIX } from "./Integrity.js";
|
|
4
|
+
|
|
5
|
+
// src/LintTable.ts
|
|
6
|
+
/**
|
|
7
|
+
* Severity a lint rule is configured to. `"info"` extends spec 4.2's
|
|
8
|
+
* `off | warn | error` so the D-34 `info` defaults are expressible.
|
|
9
|
+
*
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
const LintLevel = Schema.Literals([
|
|
13
|
+
"off",
|
|
14
|
+
"info",
|
|
15
|
+
"warn",
|
|
16
|
+
"error"
|
|
17
|
+
]).annotate({
|
|
18
|
+
title: "Lint severity",
|
|
19
|
+
description: "off — never reported; info, warn, error — the diagnostic's rendered severity.",
|
|
20
|
+
"x-taplo": { docs: { enumValues: [
|
|
21
|
+
"Never reported.",
|
|
22
|
+
"Reported as information.",
|
|
23
|
+
"Reported as a warning.",
|
|
24
|
+
"Reported as an error."
|
|
25
|
+
] } }
|
|
26
|
+
});
|
|
27
|
+
/**
|
|
28
|
+
* The `[lint]` table: one optional `LintLevel` per lint code, snake_case (D-34).
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
const LintTable = Schema.Struct({
|
|
32
|
+
broken_links: Schema.optionalKey(LintLevel.annotate({
|
|
33
|
+
title: "broken-links",
|
|
34
|
+
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\".",
|
|
35
|
+
default: "warn"
|
|
36
|
+
})),
|
|
37
|
+
missing_index: Schema.optionalKey(LintLevel.annotate({
|
|
38
|
+
title: "missing-index",
|
|
39
|
+
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\".",
|
|
40
|
+
default: "warn"
|
|
41
|
+
})),
|
|
42
|
+
unknown_type: Schema.optionalKey(LintLevel.annotate({
|
|
43
|
+
title: "unknown-type",
|
|
44
|
+
description: "A concept's type is not one of the config's declared [types.<Name>]. Default \"error\", off when no types are declared.",
|
|
45
|
+
default: "error"
|
|
46
|
+
})),
|
|
47
|
+
required_key_missing: Schema.optionalKey(LintLevel.annotate({
|
|
48
|
+
title: "required-key-missing",
|
|
49
|
+
description: "A concept is missing a frontmatter key its type or concepts.required requires. Default \"error\".",
|
|
50
|
+
default: "error"
|
|
51
|
+
})),
|
|
52
|
+
field_value_unknown: Schema.optionalKey(LintLevel.annotate({
|
|
53
|
+
title: "field-value-unknown",
|
|
54
|
+
description: "A frontmatter field's value is not one of its declared values. Default \"error\".",
|
|
55
|
+
default: "error"
|
|
56
|
+
})),
|
|
57
|
+
require_verified_unmet: Schema.optionalKey(LintLevel.annotate({
|
|
58
|
+
title: "require-verified-unmet",
|
|
59
|
+
description: "A concept whose type sets require_verified = true carries no verified entry and is not a draft. Default \"error\".",
|
|
60
|
+
default: "error"
|
|
61
|
+
})),
|
|
62
|
+
verified_before_change: Schema.optionalKey(LintLevel.annotate({
|
|
63
|
+
title: "verified-before-change",
|
|
64
|
+
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\".",
|
|
65
|
+
default: "warn"
|
|
66
|
+
})),
|
|
67
|
+
family_invalid: Schema.optionalKey(LintLevel.annotate({
|
|
68
|
+
title: "family-invalid",
|
|
69
|
+
description: `okfit's own ${INTEGRITY_KEY} family does not match its shape. Default "error".`,
|
|
70
|
+
default: "error"
|
|
71
|
+
})),
|
|
72
|
+
computation_runtime_missing: Schema.optionalKey(LintLevel.annotate({
|
|
73
|
+
title: "computation-runtime-missing",
|
|
74
|
+
description: "A referenced computation's runtime is not available. Default \"error\".",
|
|
75
|
+
default: "error"
|
|
76
|
+
})),
|
|
77
|
+
footnote_source_unknown: Schema.optionalKey(LintLevel.annotate({
|
|
78
|
+
title: "footnote-source-unknown",
|
|
79
|
+
description: "A footnote's source does not resolve. Default \"warn\".",
|
|
80
|
+
default: "warn"
|
|
81
|
+
})),
|
|
82
|
+
footnote_undefined: Schema.optionalKey(LintLevel.annotate({
|
|
83
|
+
title: "footnote-undefined",
|
|
84
|
+
description: "A footnote reference has no matching definition line in the body. Default \"warn\".",
|
|
85
|
+
default: "warn"
|
|
86
|
+
})),
|
|
87
|
+
log_frontmatter: Schema.optionalKey(LintLevel.annotate({
|
|
88
|
+
title: "log-frontmatter",
|
|
89
|
+
description: "log.md carries frontmatter, which the spec reserves against. Default \"warn\".",
|
|
90
|
+
default: "warn"
|
|
91
|
+
})),
|
|
92
|
+
actor_prefix_unknown: Schema.optionalKey(LintLevel.annotate({
|
|
93
|
+
title: "actor-prefix-unknown",
|
|
94
|
+
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\".",
|
|
95
|
+
default: "info"
|
|
96
|
+
})),
|
|
97
|
+
actor_email: Schema.optionalKey(LintLevel.annotate({
|
|
98
|
+
title: "actor-email",
|
|
99
|
+
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".`,
|
|
100
|
+
default: "warn"
|
|
101
|
+
})),
|
|
102
|
+
verified_actor_unknown: Schema.optionalKey(LintLevel.annotate({
|
|
103
|
+
title: "verified-actor-unknown",
|
|
104
|
+
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".`,
|
|
105
|
+
default: "warn"
|
|
106
|
+
})),
|
|
107
|
+
legacy_timestamp: Schema.optionalKey(LintLevel.annotate({
|
|
108
|
+
title: "legacy-timestamp",
|
|
109
|
+
description: "A concept uses the legacy timestamp field instead of generated.at. Default \"info\".",
|
|
110
|
+
default: "info"
|
|
111
|
+
})),
|
|
112
|
+
config_unknown_key: Schema.optionalKey(LintLevel.annotate({
|
|
113
|
+
title: "config-unknown-key",
|
|
114
|
+
description: "The config file declares a top-level key the schema does not recognize. Default \"warn\".",
|
|
115
|
+
default: "warn"
|
|
116
|
+
})),
|
|
117
|
+
config_okf_version_stale: Schema.optionalKey(LintLevel.annotate({
|
|
118
|
+
title: "config-okf-version-stale",
|
|
119
|
+
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\".",
|
|
120
|
+
default: "warn"
|
|
121
|
+
})),
|
|
122
|
+
stale: Schema.optionalKey(LintLevel.annotate({
|
|
123
|
+
title: "stale",
|
|
124
|
+
description: "A concept is past its stale_after instant. Default \"info\".",
|
|
125
|
+
default: "info"
|
|
126
|
+
})),
|
|
127
|
+
walk_unreadable: Schema.optionalKey(LintLevel.annotate({
|
|
128
|
+
title: "walk-unreadable",
|
|
129
|
+
description: "A directory in the bundle could not be read while walking. Default \"warn\".",
|
|
130
|
+
default: "warn"
|
|
131
|
+
})),
|
|
132
|
+
read_changed: Schema.optionalKey(LintLevel.annotate({
|
|
133
|
+
title: "read-changed",
|
|
134
|
+
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\".",
|
|
135
|
+
default: "warn"
|
|
136
|
+
})),
|
|
137
|
+
frontmatter_missing: Schema.optionalKey(LintLevel.annotate({
|
|
138
|
+
title: "frontmatter-missing",
|
|
139
|
+
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\".",
|
|
140
|
+
default: "warn"
|
|
141
|
+
})),
|
|
142
|
+
type_missing: Schema.optionalKey(LintLevel.annotate({
|
|
143
|
+
title: "type-missing",
|
|
144
|
+
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\".",
|
|
145
|
+
default: "warn"
|
|
146
|
+
})),
|
|
147
|
+
symlink_escape: Schema.optionalKey(LintLevel.annotate({
|
|
148
|
+
title: "symlink-escape",
|
|
149
|
+
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\".",
|
|
150
|
+
default: "warn"
|
|
151
|
+
})),
|
|
152
|
+
generated_at_drift: Schema.optionalKey(LintLevel.annotate({
|
|
153
|
+
title: "generated-at-drift",
|
|
154
|
+
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\".",
|
|
155
|
+
default: "warn"
|
|
156
|
+
})),
|
|
157
|
+
verified_drift: Schema.optionalKey(LintLevel.annotate({
|
|
158
|
+
title: "verified-drift",
|
|
159
|
+
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".`,
|
|
160
|
+
default: "warn"
|
|
161
|
+
})),
|
|
162
|
+
status_missing: Schema.optionalKey(LintLevel.annotate({
|
|
163
|
+
title: "status-missing",
|
|
164
|
+
description: "A concept carries neither status nor verified, so it silently reads as stable (issue #110). Off by default because the spec reads an absent status as stable; the software-project profile raises it to \"warn\".",
|
|
165
|
+
default: "off"
|
|
166
|
+
})),
|
|
167
|
+
source_resource_missing: Schema.optionalKey(LintLevel.annotate({
|
|
168
|
+
title: "source-resource-missing",
|
|
169
|
+
description: "A resource or sources[].resource path resolves neither in the bundle nor on disk relative to the concept (issue #106). Default \"warn\".",
|
|
170
|
+
default: "warn"
|
|
171
|
+
})),
|
|
172
|
+
resource_ignored: Schema.optionalKey(LintLevel.annotate({
|
|
173
|
+
title: "resource-ignored",
|
|
174
|
+
description: "A resource or sources[].resource path names a file that exists locally but is gitignored, so every other checkout sees it missing (issue #279). Skipped outside a git repository and under --skip-provenance. Default \"error\".",
|
|
175
|
+
default: "error"
|
|
176
|
+
})),
|
|
177
|
+
resource_untracked: Schema.optionalKey(LintLevel.annotate({
|
|
178
|
+
title: "resource-untracked",
|
|
179
|
+
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\".",
|
|
180
|
+
default: "warn"
|
|
181
|
+
})),
|
|
182
|
+
resource_outside_project: Schema.optionalKey(LintLevel.annotate({
|
|
183
|
+
title: "resource-outside-project",
|
|
184
|
+
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\".",
|
|
185
|
+
default: "info"
|
|
186
|
+
})),
|
|
187
|
+
superseded_by_orphan: Schema.optionalKey(LintLevel.annotate({
|
|
188
|
+
title: "superseded-by-orphan",
|
|
189
|
+
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\".",
|
|
190
|
+
default: "warn"
|
|
191
|
+
})),
|
|
192
|
+
superseded_by_unresolved: Schema.optionalKey(LintLevel.annotate({
|
|
193
|
+
title: "superseded-by-unresolved",
|
|
194
|
+
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\".",
|
|
195
|
+
default: "warn"
|
|
196
|
+
})),
|
|
197
|
+
generated_missing: Schema.optionalKey(LintLevel.annotate({
|
|
198
|
+
title: "generated-missing",
|
|
199
|
+
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.",
|
|
200
|
+
default: "warn"
|
|
201
|
+
})),
|
|
202
|
+
computation_missing: Schema.optionalKey(LintLevel.annotate({
|
|
203
|
+
title: "computation-missing",
|
|
204
|
+
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\".",
|
|
205
|
+
default: "warn"
|
|
206
|
+
})),
|
|
207
|
+
generated_at_future: Schema.optionalKey(LintLevel.annotate({
|
|
208
|
+
title: "generated-at-future",
|
|
209
|
+
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".`,
|
|
210
|
+
default: "warn"
|
|
211
|
+
})),
|
|
212
|
+
reference_not_mounted: Schema.optionalKey(LintLevel.annotate({
|
|
213
|
+
title: "reference-not-mounted",
|
|
214
|
+
description: "A named reference resolves to a declared repository, but no checkout of it is present here, so the target is not checked. Default \"info\".",
|
|
215
|
+
default: "info"
|
|
216
|
+
})),
|
|
217
|
+
reference_missing: Schema.optionalKey(LintLevel.annotate({
|
|
218
|
+
title: "reference-missing",
|
|
219
|
+
description: "A named reference resolves to a mounted checkout or the consumer's own repository, but the path it names does not exist there. Default \"warn\".",
|
|
220
|
+
default: "warn"
|
|
221
|
+
})),
|
|
222
|
+
reference_undeclared: Schema.optionalKey(LintLevel.annotate({
|
|
223
|
+
title: "reference-undeclared",
|
|
224
|
+
description: "A link uses a name:path form whose name no [references.<name>] declares, so it is read as an ordinary external link. Default \"warn\".",
|
|
225
|
+
default: "warn"
|
|
226
|
+
})),
|
|
227
|
+
reference_local_only: Schema.optionalKey(LintLevel.annotate({
|
|
228
|
+
title: "reference-local-only",
|
|
229
|
+
description: "A named reference resolves only through a checkout declared in the ignored local config file, so a clean clone cannot check it. Default \"info\".",
|
|
230
|
+
default: "info"
|
|
231
|
+
})),
|
|
232
|
+
config_misplaced_key: Schema.optionalKey(LintLevel.annotate({
|
|
233
|
+
title: "config-misplaced-key",
|
|
234
|
+
description: "A config key sits in the wrong file: a consumer-only table such as [checkouts] in a mounted bundle's own okfit.toml. The key is ignored and the message names the right file. Default \"warn\".",
|
|
235
|
+
default: "warn"
|
|
236
|
+
})),
|
|
237
|
+
config_local_tracked: Schema.optionalKey(LintLevel.annotate({
|
|
238
|
+
title: "config-local-tracked",
|
|
239
|
+
description: "The local config file (okfit.local.toml and its two other spellings) is tracked by git, so it is no longer private to one checkout. Default \"warn\".",
|
|
240
|
+
default: "warn"
|
|
241
|
+
})),
|
|
242
|
+
bundle_config_invalid: Schema.optionalKey(LintLevel.annotate({
|
|
243
|
+
title: "bundle-config-invalid",
|
|
244
|
+
description: "A mounted bundle's own okfit.toml is missing or fails to decode, or a checkout's bundle (or its okfit.toml) is a link that leaves the checkout, so the bundle cannot be validated. Default \"error\".",
|
|
245
|
+
default: "error"
|
|
246
|
+
})),
|
|
247
|
+
publication_drift: Schema.optionalKey(LintLevel.annotate({
|
|
248
|
+
title: "publication-drift",
|
|
249
|
+
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".`,
|
|
250
|
+
default: "warn"
|
|
251
|
+
})),
|
|
252
|
+
publication_orphan: Schema.optionalKey(LintLevel.annotate({
|
|
253
|
+
title: "publication-orphan",
|
|
254
|
+
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".`,
|
|
255
|
+
default: "error"
|
|
256
|
+
})),
|
|
257
|
+
surface_unmatched: Schema.optionalKey(LintLevel.annotate({
|
|
258
|
+
title: "surface-unmatched",
|
|
259
|
+
description: "A Surface's resource glob matches no file or directory; legitimate in a brand-new monorepo, so it only warns. Default \"warn\".",
|
|
260
|
+
default: "warn"
|
|
261
|
+
})),
|
|
262
|
+
index_metadata_invalid: Schema.optionalKey(LintLevel.annotate({
|
|
263
|
+
title: "index-metadata-invalid",
|
|
264
|
+
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\".",
|
|
265
|
+
default: "warn"
|
|
266
|
+
})),
|
|
267
|
+
entry_ignored: Schema.optionalKey(LintLevel.annotate({
|
|
268
|
+
title: "entry-ignored",
|
|
269
|
+
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\".",
|
|
270
|
+
default: "warn"
|
|
271
|
+
})),
|
|
272
|
+
value_malformed: Schema.optionalKey(LintLevel.annotate({
|
|
273
|
+
title: "value-malformed",
|
|
274
|
+
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\".",
|
|
275
|
+
default: "warn"
|
|
276
|
+
})),
|
|
277
|
+
value_unknown: Schema.optionalKey(LintLevel.annotate({
|
|
278
|
+
title: "value-unknown",
|
|
279
|
+
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\".",
|
|
280
|
+
default: "warn"
|
|
281
|
+
})),
|
|
282
|
+
non_concept_unlisted: Schema.optionalKey(LintLevel.annotate({
|
|
283
|
+
title: "non-concept-unlisted",
|
|
284
|
+
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\".",
|
|
285
|
+
default: "warn"
|
|
286
|
+
}))
|
|
287
|
+
}).annotate({
|
|
288
|
+
title: "Lint severities",
|
|
289
|
+
description: "Per-code severity overrides. Any key omitted keeps its default."
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
export { LintLevel, LintTable };
|
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 };
|