@okfit/core 0.15.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.
- package/Bundle.js +29 -5
- package/Concept.js +10 -0
- package/ConfinedRead.js +113 -0
- package/Derive.js +3 -3
- package/Diagnostic.js +15 -1
- package/GeneratedAtFuture.js +11 -1
- package/IndexDocument.js +3 -1
- package/LogDocument.js +3 -1
- package/OkfVersion.js +4 -1
- package/OkfitConfig.js +13 -5
- package/README.md +1 -1
- package/index.d.ts +106 -5
- package/index.js +3 -2
- package/internal/conceptDecode.js +36 -21
- package/internal/frontmatter.js +2 -2
- package/internal/linkScan.js +57 -0
- package/internal/lintRules.js +31 -12
- package/internal/reserved.js +21 -4
- package/internal/walk.js +1 -0
- package/internal/yamlPathSpan.js +82 -4
- package/package.json +5 -5
- 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",
|
|
@@ -105,6 +106,19 @@ var DiagnosticRange = class DiagnosticRange extends Schema.Class("DiagnosticRang
|
|
|
105
106
|
const span = frontmatterPathSpan(document.source, node, path);
|
|
106
107
|
return DiagnosticRange.fromOffset(document.source, span.offset, span.length);
|
|
107
108
|
};
|
|
109
|
+
/**
|
|
110
|
+
* Maps a frontmatter YAML path to the range of its last segment's own key inside `document.source`, or `undefined`
|
|
111
|
+
* when the document has no frontmatter block, the path does not end in a written mapping key, or the key is not
|
|
112
|
+
* there. For a caller that edits a key whose value has no text of its own (a bare `body:` or `body: !!null`, which
|
|
113
|
+
* {@link DiagnosticRange.forFrontmatterPath} reports as the whole block), so it can still find where the value goes.
|
|
114
|
+
*
|
|
115
|
+
* @public
|
|
116
|
+
*/
|
|
117
|
+
static forFrontmatterKey = (document, path) => {
|
|
118
|
+
const node = Option.getOrUndefined(document.frontmatter);
|
|
119
|
+
const span = node === void 0 ? void 0 : findFrontmatterKeySpan(document.source, node, path);
|
|
120
|
+
return span === void 0 ? void 0 : DiagnosticRange.fromOffset(document.source, span.offset, span.length);
|
|
121
|
+
};
|
|
108
122
|
};
|
|
109
123
|
const CONFORMANCE_CODES = new Set(ConformanceCode.literals);
|
|
110
124
|
/**
|
package/GeneratedAtFuture.js
CHANGED
|
@@ -10,6 +10,16 @@ import { DateTime, Duration, Option } from "effect";
|
|
|
10
10
|
*/
|
|
11
11
|
const GENERATED_AT_TOLERANCE = Duration.minutes(5);
|
|
12
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
|
+
/**
|
|
13
23
|
* Whether `generatedAt` is more than {@link GENERATED_AT_TOLERANCE} later than `now`. Exactly the tolerance is not
|
|
14
24
|
* future; one millisecond more is.
|
|
15
25
|
*
|
|
@@ -30,4 +40,4 @@ const verificationBlockingRestamp = (verifiedAts, generatedAt, now) => {
|
|
|
30
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());
|
|
31
41
|
};
|
|
32
42
|
|
|
33
|
-
export { GENERATED_AT_TOLERANCE, generatedAtIsFuture, verificationBlockingRestamp };
|
|
43
|
+
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/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
CHANGED
|
@@ -23,7 +23,10 @@ var OkfVersion = class OkfVersion {
|
|
|
23
23
|
};
|
|
24
24
|
/** Compares numerically, major first, so `0.10` sorts after `0.9`. */
|
|
25
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
|
-
/**
|
|
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
|
+
*/
|
|
27
30
|
static declared = (bundle) => Option.fromNullishOr(bundle.indexes.get("")?.okfVersion);
|
|
28
31
|
/** True when nothing is declared or the declared version parses and is 0.2 or earlier; an unparsable version reads as current. */
|
|
29
32
|
static allowsLegacyFallbacks = (declared) => Option.match(declared, {
|
package/OkfitConfig.js
CHANGED
|
@@ -4,6 +4,7 @@ import { GlobPattern } from "@effected/glob";
|
|
|
4
4
|
import { HostedSchema } from "@effected/schemastore";
|
|
5
5
|
import { Duration, Effect, Option, Result, Schema, SchemaGetter, SchemaIssue, SchemaTransformation } from "effect";
|
|
6
6
|
import { Actor, ActorPattern } from "./Actor.js";
|
|
7
|
+
import { GENERATED_AT_TOLERANCE_TEXT } from "./GeneratedAtFuture.js";
|
|
7
8
|
import { INTEGRITY_KEY, OKFIT_KEY_PREFIX } from "./Integrity.js";
|
|
8
9
|
|
|
9
10
|
// src/OkfitConfig.ts
|
|
@@ -131,12 +132,12 @@ const TagDeclaration = Schema.Struct({ description: Schema.optionalKey(Schema.St
|
|
|
131
132
|
const LintTable = Schema.Struct({
|
|
132
133
|
broken_links: Schema.optionalKey(LintLevel.annotate({
|
|
133
134
|
title: "broken-links",
|
|
134
|
-
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\".",
|
|
135
136
|
default: "warn"
|
|
136
137
|
})),
|
|
137
138
|
missing_index: Schema.optionalKey(LintLevel.annotate({
|
|
138
139
|
title: "missing-index",
|
|
139
|
-
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\".",
|
|
140
141
|
default: "warn"
|
|
141
142
|
})),
|
|
142
143
|
unknown_type: Schema.optionalKey(LintLevel.annotate({
|
|
@@ -229,6 +230,11 @@ const LintTable = Schema.Struct({
|
|
|
229
230
|
description: "A directory in the bundle could not be read while walking. Default \"warn\".",
|
|
230
231
|
default: "warn"
|
|
231
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
|
+
})),
|
|
232
238
|
frontmatter_missing: Schema.optionalKey(LintLevel.annotate({
|
|
233
239
|
title: "frontmatter-missing",
|
|
234
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,7 +247,7 @@ const LintTable = Schema.Struct({
|
|
|
241
247
|
})),
|
|
242
248
|
symlink_escape: Schema.optionalKey(LintLevel.annotate({
|
|
243
249
|
title: "symlink-escape",
|
|
244
|
-
description: "A file in the bundle is a symbolic link whose target lies outside the bundle root; it is not read and not part of the bundle (OKF 0.3 §3.2). Default \"warn\".",
|
|
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\".",
|
|
245
251
|
default: "warn"
|
|
246
252
|
})),
|
|
247
253
|
generated_at_drift: Schema.optionalKey(LintLevel.annotate({
|
|
@@ -291,7 +297,7 @@ const LintTable = Schema.Struct({
|
|
|
291
297
|
})),
|
|
292
298
|
generated_missing: Schema.optionalKey(LintLevel.annotate({
|
|
293
299
|
title: "generated-missing",
|
|
294
|
-
description: "A concept has no generated block while actors.agent is configured
|
|
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.",
|
|
295
301
|
default: "warn"
|
|
296
302
|
})),
|
|
297
303
|
computation_missing: Schema.optionalKey(LintLevel.annotate({
|
|
@@ -301,7 +307,7 @@ const LintTable = Schema.Struct({
|
|
|
301
307
|
})),
|
|
302
308
|
generated_at_future: Schema.optionalKey(LintLevel.annotate({
|
|
303
309
|
title: "generated-at-future",
|
|
304
|
-
description:
|
|
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".`,
|
|
305
311
|
default: "warn"
|
|
306
312
|
})),
|
|
307
313
|
publication_drift: Schema.optionalKey(LintLevel.annotate({
|
|
@@ -569,6 +575,7 @@ const LINT_KEY = {
|
|
|
569
575
|
"config-okf-version-stale": "config_okf_version_stale",
|
|
570
576
|
stale: "stale",
|
|
571
577
|
"walk-unreadable": "walk_unreadable",
|
|
578
|
+
"read-changed": "read_changed",
|
|
572
579
|
"generated-at-drift": "generated_at_drift",
|
|
573
580
|
"verified-drift": "verified_drift",
|
|
574
581
|
"status-missing": "status_missing",
|
|
@@ -614,6 +621,7 @@ const DEFAULT_LINT = {
|
|
|
614
621
|
config_okf_version_stale: "warn",
|
|
615
622
|
stale: "info",
|
|
616
623
|
walk_unreadable: "warn",
|
|
624
|
+
read_changed: "warn",
|
|
617
625
|
generated_at_drift: "warn",
|
|
618
626
|
verified_drift: "warn",
|
|
619
627
|
status_missing: "off",
|
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@ const program = Effect.gen(function* () {
|
|
|
25
25
|
|
|
26
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
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-
|
|
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.
|
|
29
29
|
|
|
30
30
|
## License
|
|
31
31
|
|
package/index.d.ts
CHANGED
|
@@ -282,6 +282,14 @@ export declare class Concept extends Concept_base {
|
|
|
282
282
|
* when `raw[family]` is not a list.
|
|
283
283
|
*/
|
|
284
284
|
static entryPath(concept: Concept, family: EntryFamily, position: number): ReadonlyArray<string | number>;
|
|
285
|
+
/**
|
|
286
|
+
* OKF 0.3 §11.2 rule 1: `undefined`, `null`, an empty string and an empty list read as absent.
|
|
287
|
+
*
|
|
288
|
+
* @remarks
|
|
289
|
+
* A mapping, `{}` included, is not absent. A family the decoder ignores (a `generated` without a readable
|
|
290
|
+
* `by`) reads as absent through the decoded `Concept`, not through this predicate.
|
|
291
|
+
*/
|
|
292
|
+
static isAbsent(value: unknown): boolean;
|
|
285
293
|
}
|
|
286
294
|
/** A posix bundle-relative path with `.md` stripped and no leading slash (D-12). @public */
|
|
287
295
|
export type ConceptId = string & Brand.Brand<"ConceptId">;
|
|
@@ -305,11 +313,11 @@ export declare const ConformanceCode: Schema.Literals<readonly ["frontmatter-unc
|
|
|
305
313
|
/** @public */
|
|
306
314
|
export type ConformanceCode = typeof ConformanceCode.Type;
|
|
307
315
|
/** Severity from `OkfitConfig` (D-34). @public */
|
|
308
|
-
export declare const LintCode: Schema.Literals<readonly ["broken-links", "missing-index", "unknown-type", "required-key-missing", "field-value-unknown", "require-verified-unmet", "verified-before-change", "family-invalid", "computation-runtime-missing", "footnote-source-unknown", "footnote-undefined", "log-frontmatter", "actor-prefix-unknown", "legacy-timestamp", "config-unknown-key", "config-okf-version-stale", "stale", "walk-unreadable", "generated-at-drift", "status-missing", "source-resource-missing", "generated-missing", "publication-drift", "publication-orphan", "surface-unmatched", "verified-drift", "actor-email", "verified-actor-unknown", "resource-ignored", "resource-untracked", "resource-outside-project", "superseded-by-orphan", "superseded-by-unresolved", "index-metadata-invalid", "entry-ignored", "value-malformed", "value-unknown", "frontmatter-missing", "type-missing", "symlink-escape", "non-concept-unlisted", "computation-missing", "generated-at-future"]>;
|
|
316
|
+
export declare const LintCode: Schema.Literals<readonly ["broken-links", "missing-index", "unknown-type", "required-key-missing", "field-value-unknown", "require-verified-unmet", "verified-before-change", "family-invalid", "computation-runtime-missing", "footnote-source-unknown", "footnote-undefined", "log-frontmatter", "actor-prefix-unknown", "legacy-timestamp", "config-unknown-key", "config-okf-version-stale", "stale", "walk-unreadable", "read-changed", "generated-at-drift", "status-missing", "source-resource-missing", "generated-missing", "publication-drift", "publication-orphan", "surface-unmatched", "verified-drift", "actor-email", "verified-actor-unknown", "resource-ignored", "resource-untracked", "resource-outside-project", "superseded-by-orphan", "superseded-by-unresolved", "index-metadata-invalid", "entry-ignored", "value-malformed", "value-unknown", "frontmatter-missing", "type-missing", "symlink-escape", "non-concept-unlisted", "computation-missing", "generated-at-future"]>;
|
|
309
317
|
/** @public */
|
|
310
318
|
export type LintCode = typeof LintCode.Type;
|
|
311
319
|
/** @public */
|
|
312
|
-
export declare const DiagnosticCode: Schema.Union<readonly [Schema.Literals<readonly ["frontmatter-unclosed", "frontmatter-unparseable", "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", "verified-before-change", "family-invalid", "computation-runtime-missing", "footnote-source-unknown", "footnote-undefined", "log-frontmatter", "actor-prefix-unknown", "legacy-timestamp", "config-unknown-key", "config-okf-version-stale", "stale", "walk-unreadable", "generated-at-drift", "status-missing", "source-resource-missing", "generated-missing", "publication-drift", "publication-orphan", "surface-unmatched", "verified-drift", "actor-email", "verified-actor-unknown", "resource-ignored", "resource-untracked", "resource-outside-project", "superseded-by-orphan", "superseded-by-unresolved", "index-metadata-invalid", "entry-ignored", "value-malformed", "value-unknown", "frontmatter-missing", "type-missing", "symlink-escape", "non-concept-unlisted", "computation-missing", "generated-at-future"]>]>;
|
|
320
|
+
export declare const DiagnosticCode: Schema.Union<readonly [Schema.Literals<readonly ["frontmatter-unclosed", "frontmatter-unparseable", "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", "verified-before-change", "family-invalid", "computation-runtime-missing", "footnote-source-unknown", "footnote-undefined", "log-frontmatter", "actor-prefix-unknown", "legacy-timestamp", "config-unknown-key", "config-okf-version-stale", "stale", "walk-unreadable", "read-changed", "generated-at-drift", "status-missing", "source-resource-missing", "generated-missing", "publication-drift", "publication-orphan", "surface-unmatched", "verified-drift", "actor-email", "verified-actor-unknown", "resource-ignored", "resource-untracked", "resource-outside-project", "superseded-by-orphan", "superseded-by-unresolved", "index-metadata-invalid", "entry-ignored", "value-malformed", "value-unknown", "frontmatter-missing", "type-missing", "symlink-escape", "non-concept-unlisted", "computation-missing", "generated-at-future"]>]>;
|
|
313
321
|
/** @public */
|
|
314
322
|
export type DiagnosticCode = typeof DiagnosticCode.Type;
|
|
315
323
|
declare const DiagnosticRange_base: Schema.Class<DiagnosticRange, Schema.Struct<{
|
|
@@ -339,11 +347,20 @@ export declare class DiagnosticRange extends DiagnosticRange_base {
|
|
|
339
347
|
* @public
|
|
340
348
|
*/
|
|
341
349
|
static readonly forFrontmatterPath: (document: MarkdownDocument, path: ReadonlyArray<string | number>) => DiagnosticRange | undefined;
|
|
350
|
+
/**
|
|
351
|
+
* Maps a frontmatter YAML path to the range of its last segment's own key inside `document.source`, or `undefined`
|
|
352
|
+
* when the document has no frontmatter block, the path does not end in a written mapping key, or the key is not
|
|
353
|
+
* there. For a caller that edits a key whose value has no text of its own (a bare `body:` or `body: !!null`, which
|
|
354
|
+
* {@link DiagnosticRange.forFrontmatterPath} reports as the whole block), so it can still find where the value goes.
|
|
355
|
+
*
|
|
356
|
+
* @public
|
|
357
|
+
*/
|
|
358
|
+
static readonly forFrontmatterKey: (document: MarkdownDocument, path: ReadonlyArray<string | number>) => DiagnosticRange | undefined;
|
|
342
359
|
}
|
|
343
360
|
declare const Diagnostic_base: Schema.Class<Diagnostic, Schema.Struct<{
|
|
344
361
|
readonly file: Schema.String;
|
|
345
362
|
readonly range: Schema.optionalKey<typeof DiagnosticRange>;
|
|
346
|
-
readonly code: Schema.Union<readonly [Schema.Literals<readonly ["frontmatter-unclosed", "frontmatter-unparseable", "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", "verified-before-change", "family-invalid", "computation-runtime-missing", "footnote-source-unknown", "footnote-undefined", "log-frontmatter", "actor-prefix-unknown", "legacy-timestamp", "config-unknown-key", "config-okf-version-stale", "stale", "walk-unreadable", "generated-at-drift", "status-missing", "source-resource-missing", "generated-missing", "publication-drift", "publication-orphan", "surface-unmatched", "verified-drift", "actor-email", "verified-actor-unknown", "resource-ignored", "resource-untracked", "resource-outside-project", "superseded-by-orphan", "superseded-by-unresolved", "index-metadata-invalid", "entry-ignored", "value-malformed", "value-unknown", "frontmatter-missing", "type-missing", "symlink-escape", "non-concept-unlisted", "computation-missing", "generated-at-future"]>]>;
|
|
363
|
+
readonly code: Schema.Union<readonly [Schema.Literals<readonly ["frontmatter-unclosed", "frontmatter-unparseable", "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", "verified-before-change", "family-invalid", "computation-runtime-missing", "footnote-source-unknown", "footnote-undefined", "log-frontmatter", "actor-prefix-unknown", "legacy-timestamp", "config-unknown-key", "config-okf-version-stale", "stale", "walk-unreadable", "read-changed", "generated-at-drift", "status-missing", "source-resource-missing", "generated-missing", "publication-drift", "publication-orphan", "surface-unmatched", "verified-drift", "actor-email", "verified-actor-unknown", "resource-ignored", "resource-untracked", "resource-outside-project", "superseded-by-orphan", "superseded-by-unresolved", "index-metadata-invalid", "entry-ignored", "value-malformed", "value-unknown", "frontmatter-missing", "type-missing", "symlink-escape", "non-concept-unlisted", "computation-missing", "generated-at-future"]>]>;
|
|
347
364
|
readonly severity: Schema.Literals<readonly ["error", "warning", "info"]>;
|
|
348
365
|
readonly message: Schema.String;
|
|
349
366
|
}>, {}>;
|
|
@@ -380,6 +397,8 @@ declare const IndexDocument_base: Schema.Class<IndexDocument, Schema.Struct<{
|
|
|
380
397
|
readonly metadata: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
381
398
|
readonly frontmatter: Schema.optionalKey<Schema.String>;
|
|
382
399
|
readonly sections: Schema.$Array<typeof IndexSection>;
|
|
400
|
+
/** The file's text as the load read it (a leading byte-order mark dropped); absent on a hand-built document. */
|
|
401
|
+
readonly source: Schema.optionalKey<Schema.String>;
|
|
383
402
|
}>, {}>;
|
|
384
403
|
/**
|
|
385
404
|
* A parsed `index.md` (D-21). The metadata fields are present only on the bundle root (OKF 0.3 section 8.1):
|
|
@@ -406,6 +425,8 @@ declare const LogDocument_base: Schema.Class<LogDocument, Schema.Struct<{
|
|
|
406
425
|
readonly dir: Schema.String;
|
|
407
426
|
readonly title: Schema.optionalKey<Schema.String>;
|
|
408
427
|
readonly groups: Schema.$Array<typeof LogGroup>;
|
|
428
|
+
/** The file's text as the load read it (a leading byte-order mark dropped); absent on a hand-built document. */
|
|
429
|
+
readonly source: Schema.optionalKey<Schema.String>;
|
|
409
430
|
}>, {}>;
|
|
410
431
|
/**
|
|
411
432
|
* A parsed `log.md` (D-21).
|
|
@@ -471,7 +492,7 @@ interface BundleLoadOptions {
|
|
|
471
492
|
readonly includeHidden?: boolean;
|
|
472
493
|
/** Directory levels below the root to descend; positive integer, default 256; exceeding it fails with `BundleDepthExceededError`. */
|
|
473
494
|
readonly maxDepth?: number;
|
|
474
|
-
/** Directory names never descended (default `["node_modules", ".git"]`). */
|
|
495
|
+
/** Directory names never descended (default `["node_modules", ".git"]`); a symbolic link with one of these names is skipped unread, while a regular file with one is still loaded. */
|
|
475
496
|
readonly prune?: ReadonlyArray<string>;
|
|
476
497
|
}
|
|
477
498
|
declare const LoadedConcept_base: Schema.Class<LoadedConcept, Schema.Struct<{
|
|
@@ -549,9 +570,75 @@ export declare class Bundle {
|
|
|
549
570
|
* fails: every bad file becomes a diagnostic and loading continues (spec 8). A walk
|
|
550
571
|
* that descends past `options.maxDepth` fails typed with `BundleDepthExceededError`
|
|
551
572
|
* (W-1) rather than being silently truncated.
|
|
573
|
+
*
|
|
574
|
+
* A symbolic link is never followed out of the bundle (OKF 0.3 section 3.2 rule 5). A file link that leaves
|
|
575
|
+
* it, a directory link that leaves it (nothing under it is read), and a link of either kind whose resolution
|
|
576
|
+
* fails (dangling, a loop, an unreadable target) each record a `symlink-escape` warning at their own path
|
|
577
|
+
* (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
|
|
578
|
+
* records nothing. Each Markdown file is read confined (`readConfinedString`): a file that becomes a link out of
|
|
579
|
+
* the bundle between the link check and the read is refused as `symlink-escape`, and one that changed under the
|
|
580
|
+
* read (`changed`) is recorded `read-changed` ("try again") and left out of that load. A race through a directory above
|
|
581
|
+
* the file can still win (spencerbeggs/okfit#524).
|
|
552
582
|
*/
|
|
553
583
|
static readonly load: (options: BundleLoadOptions) => Effect.Effect<LoadedBundle, BundleLoadError, FileSystem.FileSystem | Path.Path>;
|
|
554
584
|
}
|
|
585
|
+
/**
|
|
586
|
+
* The transient wording every surface uses for a file that changed under a read: the quoted `subject` (a path or
|
|
587
|
+
* a concept file name) followed by `changed while it was read; try again`. One spelling, so the CLI, the MCP server
|
|
588
|
+
* and `ConfinementError` never drift. It is never an escape verdict.
|
|
589
|
+
*
|
|
590
|
+
* @public
|
|
591
|
+
*/
|
|
592
|
+
export declare const changedWhileRead: (subject: string) => string;
|
|
593
|
+
declare const ConfinementError_base: Schema.Class<ConfinementError, Schema.TaggedStruct<"ConfinementError", {
|
|
594
|
+
readonly root: Schema.String;
|
|
595
|
+
/** The path that was read, as it was given. */
|
|
596
|
+
readonly path: Schema.String;
|
|
597
|
+
readonly reason: Schema.Literals<readonly ["outside", "unresolvable", "changed"]>;
|
|
598
|
+
}>, import("effect/Cause").YieldableError>;
|
|
599
|
+
/**
|
|
600
|
+
* A file read was refused (OKF 0.3 section 3.2).
|
|
601
|
+
*
|
|
602
|
+
* `reason` says why: `outside` (a link on the path resolves outside the root), `unresolvable` (a link on the path
|
|
603
|
+
* dangles or cannot be resolved) or `changed` (the path no longer names the file that was opened, or what it names
|
|
604
|
+
* could not be compared: it was swapped, replaced or removed while it was read, so reading again may succeed). Only
|
|
605
|
+
* `outside` and `unresolvable` mean the path leaves the bundle; `changed` is transient and never an escape verdict.
|
|
606
|
+
*
|
|
607
|
+
* @public
|
|
608
|
+
*/
|
|
609
|
+
export declare class ConfinementError extends ConfinementError_base {
|
|
610
|
+
get message(): string;
|
|
611
|
+
}
|
|
612
|
+
/**
|
|
613
|
+
* Read the file `target` (an absolute path) under `root` confined to it, so a link swapped in after a check is not
|
|
614
|
+
* read: open the file, resolve the path with `confineReal` (every link on it, at the file or at a directory above
|
|
615
|
+
* it), require that the path still exists (`realPath`), then require that the open file is the file the resolved
|
|
616
|
+
* path names (`dev` and `ino` of the open file's `stat` against `lstat` of the real path, which must itself be a
|
|
617
|
+
* file and not a link). The bytes come from the open file, never from a second open of the path.
|
|
618
|
+
*
|
|
619
|
+
* The guarantee is exact about one case: a link at the file itself, swapped in at any moment during the read, is
|
|
620
|
+
* refused. A race through a directory above the file can still win, because the open and the resolution are
|
|
621
|
+
* separate steps on the path (spencerbeggs/okfit#524); there is no retry, which would only widen that window.
|
|
622
|
+
*
|
|
623
|
+
* It fails with {@link ConfinementError} (`outside` or `unresolvable` when a link on the path leaves the root or
|
|
624
|
+
* dangles; `changed` when the path no longer names the file that was opened, or either stat lacks an `ino`), and
|
|
625
|
+
* with the `PlatformError` of the open or the read otherwise. A missing file is that `PlatformError` (`NotFound`)
|
|
626
|
+
* unless a link on its path escapes or dangles. A hard link to a file under the root is a file under the root
|
|
627
|
+
* (OKF 0.3 section 3.2) and is read.
|
|
628
|
+
*
|
|
629
|
+
* Only reads are confined this way. A write stays a check followed by `writeAtomic`.
|
|
630
|
+
*
|
|
631
|
+
* @public
|
|
632
|
+
*/
|
|
633
|
+
export declare const readConfinedBytes: (root: string, target: string) => Effect.Effect<Uint8Array<ArrayBuffer>, ConfinementError | import("effect/PlatformError").PlatformError, FileSystem.FileSystem | import("effect/Path").Path>;
|
|
634
|
+
/**
|
|
635
|
+
* {@link readConfinedBytes} decoded as UTF-8. A leading byte-order mark is dropped, as Effect's
|
|
636
|
+
* `FileSystem.readFileString` (a `TextDecoder`) drops it, so the loader reads a BOM file as it always did and a
|
|
637
|
+
* writer gives the BOM back.
|
|
638
|
+
*
|
|
639
|
+
* @public
|
|
640
|
+
*/
|
|
641
|
+
export declare const readConfinedString: (root: string, target: string) => Effect.Effect<string, ConfinementError | import("effect/PlatformError").PlatformError, FileSystem.FileSystem | import("effect/Path").Path>;
|
|
555
642
|
/**
|
|
556
643
|
* Concept lifecycle status. Absent on a concept means `stable` (`Derive.status`).
|
|
557
644
|
* @public
|
|
@@ -718,6 +805,13 @@ export declare class Derive {
|
|
|
718
805
|
* @public
|
|
719
806
|
*/
|
|
720
807
|
export declare const GENERATED_AT_TOLERANCE: Duration.Duration;
|
|
808
|
+
/**
|
|
809
|
+
* {@link GENERATED_AT_TOLERANCE} in words ("5 minutes"), for messages. Derived from the constant, so changing the
|
|
810
|
+
* tolerance changes every message that names it. The tolerance is a whole number of minutes.
|
|
811
|
+
*
|
|
812
|
+
* @public
|
|
813
|
+
*/
|
|
814
|
+
export declare const GENERATED_AT_TOLERANCE_TEXT: string;
|
|
721
815
|
/**
|
|
722
816
|
* Whether `generatedAt` is more than {@link GENERATED_AT_TOLERANCE} later than `now`. Exactly the tolerance is not
|
|
723
817
|
* future; one millisecond more is.
|
|
@@ -930,6 +1024,7 @@ export declare const LintTable: Schema.Struct<{
|
|
|
930
1024
|
readonly config_okf_version_stale: Schema.optionalKey<Schema.Literals<readonly ["off", "info", "warn", "error"]>>;
|
|
931
1025
|
readonly stale: Schema.optionalKey<Schema.Literals<readonly ["off", "info", "warn", "error"]>>;
|
|
932
1026
|
readonly walk_unreadable: Schema.optionalKey<Schema.Literals<readonly ["off", "info", "warn", "error"]>>;
|
|
1027
|
+
readonly read_changed: Schema.optionalKey<Schema.Literals<readonly ["off", "info", "warn", "error"]>>;
|
|
933
1028
|
readonly frontmatter_missing: Schema.optionalKey<Schema.Literals<readonly ["off", "info", "warn", "error"]>>;
|
|
934
1029
|
readonly type_missing: Schema.optionalKey<Schema.Literals<readonly ["off", "info", "warn", "error"]>>;
|
|
935
1030
|
readonly symlink_escape: Schema.optionalKey<Schema.Literals<readonly ["off", "info", "warn", "error"]>>;
|
|
@@ -1001,6 +1096,7 @@ declare const okfitConfigFields: Schema.Struct<{
|
|
|
1001
1096
|
readonly config_okf_version_stale: Schema.optionalKey<Schema.Literals<readonly ["off", "info", "warn", "error"]>>;
|
|
1002
1097
|
readonly stale: Schema.optionalKey<Schema.Literals<readonly ["off", "info", "warn", "error"]>>;
|
|
1003
1098
|
readonly walk_unreadable: Schema.optionalKey<Schema.Literals<readonly ["off", "info", "warn", "error"]>>;
|
|
1099
|
+
readonly read_changed: Schema.optionalKey<Schema.Literals<readonly ["off", "info", "warn", "error"]>>;
|
|
1004
1100
|
readonly frontmatter_missing: Schema.optionalKey<Schema.Literals<readonly ["off", "info", "warn", "error"]>>;
|
|
1005
1101
|
readonly type_missing: Schema.optionalKey<Schema.Literals<readonly ["off", "info", "warn", "error"]>>;
|
|
1006
1102
|
readonly symlink_escape: Schema.optionalKey<Schema.Literals<readonly ["off", "info", "warn", "error"]>>;
|
|
@@ -1125,6 +1221,7 @@ export declare const okfitConfigDocumentFields: Schema.StructWithRest<Schema.Str
|
|
|
1125
1221
|
readonly config_okf_version_stale: Schema.optionalKey<Schema.Literals<readonly ["off", "info", "warn", "error"]>>;
|
|
1126
1222
|
readonly stale: Schema.optionalKey<Schema.Literals<readonly ["off", "info", "warn", "error"]>>;
|
|
1127
1223
|
readonly walk_unreadable: Schema.optionalKey<Schema.Literals<readonly ["off", "info", "warn", "error"]>>;
|
|
1224
|
+
readonly read_changed: Schema.optionalKey<Schema.Literals<readonly ["off", "info", "warn", "error"]>>;
|
|
1128
1225
|
readonly frontmatter_missing: Schema.optionalKey<Schema.Literals<readonly ["off", "info", "warn", "error"]>>;
|
|
1129
1226
|
readonly type_missing: Schema.optionalKey<Schema.Literals<readonly ["off", "info", "warn", "error"]>>;
|
|
1130
1227
|
readonly symlink_escape: Schema.optionalKey<Schema.Literals<readonly ["off", "info", "warn", "error"]>>;
|
|
@@ -1237,6 +1334,7 @@ declare const OkfitConfigFile_base: import("effect/Context").ServiceClass<OkfitC
|
|
|
1237
1334
|
readonly config_okf_version_stale?: "error" | "info" | "off" | "warn";
|
|
1238
1335
|
readonly stale?: "error" | "info" | "off" | "warn";
|
|
1239
1336
|
readonly walk_unreadable?: "error" | "info" | "off" | "warn";
|
|
1337
|
+
readonly read_changed?: "error" | "info" | "off" | "warn";
|
|
1240
1338
|
readonly frontmatter_missing?: "error" | "info" | "off" | "warn";
|
|
1241
1339
|
readonly type_missing?: "error" | "info" | "off" | "warn";
|
|
1242
1340
|
readonly symlink_escape?: "error" | "info" | "off" | "warn";
|
|
@@ -1316,7 +1414,10 @@ export declare class OkfVersion {
|
|
|
1316
1414
|
static readonly parse: (raw: string) => Option.Option<OkfVersionNumber>;
|
|
1317
1415
|
/** Compares numerically, major first, so `0.10` sorts after `0.9`. */
|
|
1318
1416
|
static readonly compare: (a: OkfVersionNumber, b: OkfVersionNumber) => -1 | 0 | 1;
|
|
1319
|
-
/**
|
|
1417
|
+
/**
|
|
1418
|
+
* The version the bundle-root `index.md` declares, as written; `None` when there is no root index or no `okf_version`.
|
|
1419
|
+
* An unquoted number is its source text (`0.10`, not `0.1`).
|
|
1420
|
+
*/
|
|
1320
1421
|
static readonly declared: (bundle: LoadedBundle) => Option.Option<string>;
|
|
1321
1422
|
/** True when nothing is declared or the declared version parses and is 0.2 or earlier; an unparsable version reads as current. */
|
|
1322
1423
|
static readonly allowsLegacyFallbacks: (declared: Option.Option<string>) => boolean;
|
package/index.js
CHANGED
|
@@ -3,10 +3,11 @@ import { AttestedComputation, ComputationAttester, ComputationExecutor, Computat
|
|
|
3
3
|
import { Bundle, BundleDepthExceededError, BundleReadError, BundleRootNotFoundError, LoadedBundle, LoadedConcept } from "./Bundle.js";
|
|
4
4
|
import { ATTESTED_COMPUTATION_TYPE, Concept, EntryPaths } from "./Concept.js";
|
|
5
5
|
import { ConceptId } from "./ConceptId.js";
|
|
6
|
+
import { ConfinementError, changedWhileRead, readConfinedBytes, readConfinedString } from "./ConfinedRead.js";
|
|
6
7
|
import { Derive, Staleness, TrustTier } from "./Derive.js";
|
|
7
8
|
import { ConformanceCode, Diagnostic, DiagnosticCode, DiagnosticRange, DiagnosticSeverity, LintCode } from "./Diagnostic.js";
|
|
8
9
|
import { Generated } from "./Generated.js";
|
|
9
|
-
import { GENERATED_AT_TOLERANCE, generatedAtIsFuture, verificationBlockingRestamp } from "./GeneratedAtFuture.js";
|
|
10
|
+
import { GENERATED_AT_TOLERANCE, GENERATED_AT_TOLERANCE_TEXT, generatedAtIsFuture, verificationBlockingRestamp } from "./GeneratedAtFuture.js";
|
|
10
11
|
import { Graph, GraphNodeKind, LinkGraph } from "./Graph.js";
|
|
11
12
|
import { IndexDocument, IndexEntry, IndexSection } from "./IndexDocument.js";
|
|
12
13
|
import { Digest, INTEGRITY_KEY, Integrity, IntegrityGenerated, IntegrityVerified, OKFIT_KEY_PREFIX } from "./Integrity.js";
|
|
@@ -27,4 +28,4 @@ import { Verification } from "./Verification.js";
|
|
|
27
28
|
*/
|
|
28
29
|
const OKF_SPEC_VERSION = "0.3";
|
|
29
30
|
|
|
30
|
-
export { ATTESTED_COMPUTATION_TYPE, Actor, ActorPattern, AttestedComputation, Bundle, BundleDepthExceededError, BundleReadError, BundleRootNotFoundError, CONFIG_SCHEMA_VERSION, ComputationAttester, ComputationExecutor, ComputationParameter, Concept, ConceptId, ConformanceCode, Derive, DerivedStatus, Diagnostic, DiagnosticCode, DiagnosticRange, DiagnosticSeverity, Digest, EntryPaths, FieldDeclaration, GENERATED_AT_TOLERANCE, Generated, Graph, GraphNodeKind, INTEGRITY_KEY, IndexDocument, IndexEntry, IndexSection, Integrity, IntegrityGenerated, IntegrityVerified, LinkGraph, LintCode, LintLevel, LintTable, LoadedBundle, LoadedConcept, LogDocument, LogGroup, LogItem, OKFIT_KEY_PREFIX, OKF_SPEC_VERSION, OkfVersion, OkfitConfig, OkfitConfigFile, SCHEMA_DIRECTIVE, Source, StaleAfterDuration, Staleness, Status, TagDeclaration, Timestamp, TrustTier, TypeDeclaration, UsageWindow, Validate, Verification, generatedAtIsFuture, okfitConfigDocumentFields, okfitConfigSchemaHost, verificationBlockingRestamp };
|
|
31
|
+
export { ATTESTED_COMPUTATION_TYPE, Actor, ActorPattern, AttestedComputation, Bundle, BundleDepthExceededError, BundleReadError, BundleRootNotFoundError, CONFIG_SCHEMA_VERSION, ComputationAttester, ComputationExecutor, ComputationParameter, Concept, ConceptId, ConfinementError, ConformanceCode, Derive, DerivedStatus, Diagnostic, DiagnosticCode, DiagnosticRange, DiagnosticSeverity, Digest, EntryPaths, FieldDeclaration, GENERATED_AT_TOLERANCE, GENERATED_AT_TOLERANCE_TEXT, Generated, Graph, GraphNodeKind, INTEGRITY_KEY, IndexDocument, IndexEntry, IndexSection, Integrity, IntegrityGenerated, IntegrityVerified, LinkGraph, LintCode, LintLevel, LintTable, LoadedBundle, LoadedConcept, LogDocument, LogGroup, LogItem, OKFIT_KEY_PREFIX, OKF_SPEC_VERSION, OkfVersion, OkfitConfig, OkfitConfigFile, SCHEMA_DIRECTIVE, Source, StaleAfterDuration, Staleness, Status, TagDeclaration, Timestamp, TrustTier, TypeDeclaration, UsageWindow, Validate, Verification, changedWhileRead, generatedAtIsFuture, okfitConfigDocumentFields, okfitConfigSchemaHost, readConfinedBytes, readConfinedString, verificationBlockingRestamp };
|
|
@@ -30,12 +30,6 @@ const SCALAR_SCHEMAS = {
|
|
|
30
30
|
const PARSE_OPTIONS = { errors: "all" };
|
|
31
31
|
const formatIssue = SchemaIssue.makeFormatterStandardSchemaV1();
|
|
32
32
|
const isMapping = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
33
|
-
/**
|
|
34
|
-
* OKF 0.3 11.2 rule 1: `null`, an empty string and an empty list read as absent.
|
|
35
|
-
*
|
|
36
|
-
* @internal
|
|
37
|
-
*/
|
|
38
|
-
const isAbsent = (value) => value === void 0 || value === null || value === "" || Array.isArray(value) && value.length === 0;
|
|
39
33
|
const leafMessages = (failure) => formatIssue(failure.issue).issues.map((leaf) => ({
|
|
40
34
|
path: (leaf.path ?? []).filter((segment) => typeof segment !== "symbol"),
|
|
41
35
|
message: leaf.message
|
|
@@ -55,11 +49,14 @@ const decodeFamily = (schema, family, prefix, value, issues, code = "value-malfo
|
|
|
55
49
|
* Decode a mapping key by key against a class's declared fields (OKF 0.3 11.2 rule 3). Each
|
|
56
50
|
* declared key is decoded alone: a REQUIRED key that is missing or unreadable ignores the whole
|
|
57
51
|
* mapping (`entry-ignored`, returns `undefined`); any other key that is unreadable is dropped
|
|
58
|
-
* alone (`value-malformed` at `[...path, key]`). Keys the class does not declare are never read
|
|
52
|
+
* alone (`value-malformed` at `[...path, key]`). Keys the class does not declare are never read, so
|
|
53
|
+
* an unknown key never keeps a mapping present (see {@link decodeNested}). A key listed in `nested`
|
|
54
|
+
* is itself a declared mapping and is decoded key by key at `[...path, key]`, so one bad key inside
|
|
55
|
+
* it drops that key alone.
|
|
59
56
|
*
|
|
60
57
|
* @internal
|
|
61
58
|
*/
|
|
62
|
-
const decodeMapping = (fields, required, value, path, family, issues) => {
|
|
59
|
+
const decodeMapping = (fields, required, value, path, family, issues, nested = {}) => {
|
|
63
60
|
if (!isMapping(value)) {
|
|
64
61
|
issues.push({
|
|
65
62
|
code: required.length > 0 ? "entry-ignored" : "value-malformed",
|
|
@@ -81,8 +78,15 @@ const decodeMapping = (fields, required, value, path, family, issues) => {
|
|
|
81
78
|
};
|
|
82
79
|
for (const key of Object.keys(fields)) {
|
|
83
80
|
const isRequired = required.includes(key);
|
|
84
|
-
const present = Object.hasOwn(value, key) && !isAbsent(value[key]);
|
|
81
|
+
const present = Object.hasOwn(value, key) && !Concept.isAbsent(value[key]);
|
|
85
82
|
if (isRequired && !present) return ignore(`\`${key}\` is required`);
|
|
83
|
+
const inner = Object.hasOwn(nested, key) ? nested[key] : void 0;
|
|
84
|
+
if (inner !== void 0) {
|
|
85
|
+
if (!present) continue;
|
|
86
|
+
const kept = decodeNested(inner.cls, inner.required, value[key], [...path, key], family, dropped);
|
|
87
|
+
if (kept !== void 0) out[key] = kept;
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
86
90
|
const schema = Schema.Struct({ [key]: fields[key] });
|
|
87
91
|
const result = Schema.decodeUnknownResult(schema, PARSE_OPTIONS)(present ? { [key]: value[key] } : {});
|
|
88
92
|
if (Result.isSuccess(result)) {
|
|
@@ -131,11 +135,11 @@ const itemsOf = (key, value) => Array.isArray(value) ? value.map((item, index) =
|
|
|
131
135
|
path: [key]
|
|
132
136
|
}];
|
|
133
137
|
/** Decode a list family of mappings; returns the kept values with their YAML paths, or `undefined` when none survive. */
|
|
134
|
-
const decodeMappingList = (key, family, value, cls, required, issues) => {
|
|
138
|
+
const decodeMappingList = (key, family, value, cls, required, issues, nested = {}) => {
|
|
135
139
|
const values = [];
|
|
136
140
|
const paths = [];
|
|
137
141
|
for (const { item, path } of itemsOf(key, value)) {
|
|
138
|
-
const decoded = decodeMapping(cls.fields, required, item, path, family, issues);
|
|
142
|
+
const decoded = decodeMapping(cls.fields, required, item, path, family, issues, nested);
|
|
139
143
|
if (decoded === void 0) continue;
|
|
140
144
|
const built = build(cls, decoded, path, family, issues);
|
|
141
145
|
if (built === void 0) continue;
|
|
@@ -147,24 +151,32 @@ const decodeMappingList = (key, family, value, cls, required, issues) => {
|
|
|
147
151
|
paths
|
|
148
152
|
};
|
|
149
153
|
};
|
|
150
|
-
/**
|
|
151
|
-
|
|
152
|
-
|
|
154
|
+
/**
|
|
155
|
+
* Decode one mapping value key by key (a top-level family, or a declared mapping nested in another).
|
|
156
|
+
*
|
|
157
|
+
* "Emptied by dropped keys" counts only the class's declared keys: a mapping with at least one
|
|
158
|
+
* dropped key and no kept declared key reads as absent, whatever unknown keys it also has. A mapping
|
|
159
|
+
* with no dropped key is kept, even when it holds nothing but unknown keys (`{ x: 1 }`, like `{}`).
|
|
160
|
+
* Unknown keys stay in `raw` and are never read (OKF 0.3 11.2: never rejected).
|
|
161
|
+
*/
|
|
162
|
+
const decodeNested = (cls, required, value, path, family, issues) => {
|
|
153
163
|
const before = issues.length;
|
|
154
|
-
const decoded = decodeMapping(cls.fields, required,
|
|
164
|
+
const decoded = decodeMapping(cls.fields, required, value, path, family, issues);
|
|
155
165
|
if (decoded === void 0) return void 0;
|
|
156
166
|
if (Object.keys(decoded).length === 0 && issues.length > before) return void 0;
|
|
157
|
-
return build(cls, decoded,
|
|
167
|
+
return build(cls, decoded, path, family, issues);
|
|
158
168
|
};
|
|
169
|
+
/** Decode one single-mapping key; absent (rule 1) or unreadable reads as `undefined`. */
|
|
170
|
+
const decodeSingle = (key, family, raw, cls, required, issues) => Concept.isAbsent(raw[key]) ? void 0 : decodeNested(cls, required, raw[key], [key], family, issues);
|
|
159
171
|
/** Decode the computation keys independently (a bad `executor` no longer drops `runtime`). */
|
|
160
172
|
const decodeAttested = (raw, issues, entries) => {
|
|
161
173
|
const input = { parameters: [] };
|
|
162
174
|
for (const key of ["runtime", "computation"]) {
|
|
163
|
-
if (isAbsent(raw[key])) continue;
|
|
175
|
+
if (Concept.isAbsent(raw[key])) continue;
|
|
164
176
|
const decoded = decodeFamily(Schema.String, "attested", [key], raw[key], issues);
|
|
165
177
|
if (decoded !== void 0) input[key] = decoded;
|
|
166
178
|
}
|
|
167
|
-
if (!isAbsent(raw.parameters)) {
|
|
179
|
+
if (!Concept.isAbsent(raw.parameters)) {
|
|
168
180
|
const list = decodeMappingList("parameters", "attested", raw.parameters, ComputationParameter, ["name", "type"], issues);
|
|
169
181
|
if (list !== void 0) {
|
|
170
182
|
input.parameters = list.values;
|
|
@@ -221,7 +233,7 @@ const decodeConcept = (value) => {
|
|
|
221
233
|
};
|
|
222
234
|
const out = fields;
|
|
223
235
|
const entries = {};
|
|
224
|
-
const present = (key) => key in raw && !isAbsent(raw[key]);
|
|
236
|
+
const present = (key) => key in raw && !Concept.isAbsent(raw[key]);
|
|
225
237
|
const scalar = (key) => {
|
|
226
238
|
if (!present(key)) return;
|
|
227
239
|
const decoded = decodeFamily(SCALAR_SCHEMAS[key], key, [key], raw[key], issues);
|
|
@@ -254,7 +266,10 @@ const decodeConcept = (value) => {
|
|
|
254
266
|
}
|
|
255
267
|
}
|
|
256
268
|
if (present("sources")) {
|
|
257
|
-
const list = decodeMappingList("sources", "sources", raw.sources, Source, ["resource"], issues
|
|
269
|
+
const list = decodeMappingList("sources", "sources", raw.sources, Source, ["resource"], issues, { usage_window: {
|
|
270
|
+
cls: UsageWindow,
|
|
271
|
+
required: []
|
|
272
|
+
} });
|
|
258
273
|
if (list !== void 0) {
|
|
259
274
|
out.sources = list.values;
|
|
260
275
|
entries.sources = list.paths;
|
|
@@ -318,4 +333,4 @@ const decodeConcept = (value) => {
|
|
|
318
333
|
};
|
|
319
334
|
};
|
|
320
335
|
|
|
321
|
-
export { COMPUTATION_KEYS, decodeConcept, decodeMapping
|
|
336
|
+
export { COMPUTATION_KEYS, decodeConcept, decodeMapping };
|
package/internal/frontmatter.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Option } from "effect";
|
|
2
2
|
import { Diagnostic, DiagnosticRange } from "../Diagnostic.js";
|
|
3
3
|
import { decodeConcept as decodeConcept$1 } from "./conceptDecode.js";
|
|
4
|
-
import {
|
|
4
|
+
import { frontmatterAnchorSpan } from "./yamlPathSpan.js";
|
|
5
5
|
|
|
6
6
|
// src/internal/frontmatter.ts
|
|
7
7
|
/** D-34 default severities for a `FamilyIssue`'s lint code. */
|
|
@@ -14,7 +14,7 @@ const FAMILY_ISSUE_SEVERITY = {
|
|
|
14
14
|
"value-unknown": "warning"
|
|
15
15
|
};
|
|
16
16
|
const spanToRange = (text, path, node) => {
|
|
17
|
-
const span =
|
|
17
|
+
const span = frontmatterAnchorSpan(text, node, path);
|
|
18
18
|
return DiagnosticRange.fromOffset(text, span.offset, span.length);
|
|
19
19
|
};
|
|
20
20
|
/**
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { confineReal } from "@effected/walker";
|
|
2
|
+
import { Effect, Path } from "effect";
|
|
3
|
+
|
|
4
|
+
// src/internal/linkScan.ts
|
|
5
|
+
/** The words a `symlink-escape` message uses for a link that leaves the bundle root; one spelling for every site. */
|
|
6
|
+
const RESOLVES_OUTSIDE = "resolves outside the bundle root";
|
|
7
|
+
/** The words a `symlink-escape` message uses for a link that cannot be resolved (dangling, a loop, unreadable). */
|
|
8
|
+
const COULD_NOT_RESOLVE = "could not be resolved, so it cannot be shown to stay inside the bundle root";
|
|
9
|
+
const byPath = (a, b) => a.file < b.file ? -1 : a.file > b.file ? 1 : 0;
|
|
10
|
+
/**
|
|
11
|
+
* The walker's `links` report as `symlink-escape` findings: a link to a directory that resolves outside the bundle (the
|
|
12
|
+
* walker never enters one, wherever it points), and a link that does not resolve (dangling, whether it named a file or
|
|
13
|
+
* a directory). A directory link is decided on its REAL path with `confineReal`, so a link inside the bundle that points
|
|
14
|
+
* at a link leaving it is refused too; one that stays inside (or is the bundle root itself) is silent and never walked.
|
|
15
|
+
* Directory findings come first, then the unresolvable ones, each sorted by path.
|
|
16
|
+
*
|
|
17
|
+
* @remarks
|
|
18
|
+
* The walker reports links only from directories it reads, so a pruned directory, a hidden one and anything under them
|
|
19
|
+
* are never seen. It reports a dangling link whatever its own name, so a pruned or (without `includeHidden`) hidden name
|
|
20
|
+
* is dropped here to keep Q8: a pruned directory name is fully silent, and a hidden name is reported only with
|
|
21
|
+
* `includeHidden`. A file link with a pruned name is a file match, not a skipped link; `Bundle.load` drops it
|
|
22
|
+
* silently too (never read, never reported), so the prune list silences a name for files and directories alike.
|
|
23
|
+
*
|
|
24
|
+
* @internal
|
|
25
|
+
*/
|
|
26
|
+
const scanLinks = (root, links, options) => Effect.gen(function* () {
|
|
27
|
+
const path = yield* Path.Path;
|
|
28
|
+
const silent = (link) => {
|
|
29
|
+
const name = link.slice(link.lastIndexOf("/") + 1);
|
|
30
|
+
return options.prune.has(name) || !options.includeHidden && name.startsWith(".");
|
|
31
|
+
};
|
|
32
|
+
const directories = [];
|
|
33
|
+
const unresolvable = [];
|
|
34
|
+
for (const link of links) {
|
|
35
|
+
if (silent(link.path)) continue;
|
|
36
|
+
if (link.kind === "special") continue;
|
|
37
|
+
if (link.kind === "dangling") {
|
|
38
|
+
unresolvable.push({
|
|
39
|
+
file: link.path,
|
|
40
|
+
message: `symbolic link ${COULD_NOT_RESOLVE}; it is not read and not part of the bundle`
|
|
41
|
+
});
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
const reason = yield* confineReal(root, path.join(root, link.path)).pipe(Effect.match({
|
|
45
|
+
onFailure: (error) => error.reason,
|
|
46
|
+
onSuccess: () => void 0
|
|
47
|
+
}));
|
|
48
|
+
if (reason === void 0 || reason === "empty") continue;
|
|
49
|
+
directories.push({
|
|
50
|
+
file: link.path,
|
|
51
|
+
message: `symbolic link to a directory ${reason === "outside" ? RESOLVES_OUTSIDE : COULD_NOT_RESOLVE}; nothing under it is read or part of the bundle`
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
return [...directories.sort(byPath), ...unresolvable.sort(byPath)];
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
export { COULD_NOT_RESOLVE, RESOLVES_OUTSIDE, scanLinks };
|
package/internal/lintRules.js
CHANGED
|
@@ -5,18 +5,19 @@ import { Actor } from "../Actor.js";
|
|
|
5
5
|
import { Concept } from "../Concept.js";
|
|
6
6
|
import { Derive } from "../Derive.js";
|
|
7
7
|
import { Diagnostic, DiagnosticRange } from "../Diagnostic.js";
|
|
8
|
-
import {
|
|
8
|
+
import { Generated } from "../Generated.js";
|
|
9
|
+
import { GENERATED_AT_TOLERANCE_TEXT, generatedAtIsFuture, verificationBlockingRestamp } from "../GeneratedAtFuture.js";
|
|
9
10
|
import { Graph as Graph$1 } from "../Graph.js";
|
|
10
11
|
import { INTEGRITY_KEY } from "../Integrity.js";
|
|
11
12
|
import { OkfVersion } from "../OkfVersion.js";
|
|
12
13
|
import { Timestamp } from "../Timestamp.js";
|
|
13
|
-
import { isAbsent } from "./conceptDecode.js";
|
|
14
14
|
import { frontmatterPathRange } from "./frontmatter.js";
|
|
15
15
|
import { tierOf } from "./tier.js";
|
|
16
|
+
import { isReplaceableNull } from "./yamlPathSpan.js";
|
|
16
17
|
|
|
17
18
|
// src/internal/lintRules.ts
|
|
18
19
|
/** OKF 0.3 §11.2 rule 1: a key holding null, the empty string or the empty list is absent. */
|
|
19
|
-
const present = (raw, key) => Object.hasOwn(raw, key) && !isAbsent(raw[key]);
|
|
20
|
+
const present = (raw, key) => Object.hasOwn(raw, key) && !Concept.isAbsent(raw[key]);
|
|
20
21
|
const diagnostic = (file, code, severity, message, range) => Diagnostic.make({
|
|
21
22
|
file,
|
|
22
23
|
code,
|
|
@@ -57,16 +58,17 @@ const configOkfVersionStale = rule("config-okf-version-stale", (context, severit
|
|
|
57
58
|
});
|
|
58
59
|
/**
|
|
59
60
|
* #471: a `generated.at` later than now counts for no verification (OKF 0.3 §5.3) and `okfit verify` refuses it;
|
|
60
|
-
* `okfit sync` re-stamps it, except when a verification would then count
|
|
61
|
+
* `okfit sync` re-stamps it to now (a file with uncommitted edits is skipped until they are committed), except when a verification would then count
|
|
62
|
+
* (`verificationBlockingRestamp`).
|
|
61
63
|
*/
|
|
62
64
|
const generatedAtFuture = perConcept("generated-at-future", (concept, context) => {
|
|
63
65
|
const at = concept.frontmatter.generated?.at;
|
|
64
66
|
const { now } = context;
|
|
65
67
|
if (at === void 0 || now === void 0 || !generatedAtIsFuture(at, now)) return [];
|
|
66
|
-
const head = `generated.at ${instant(at)} is more than
|
|
68
|
+
const head = `generated.at ${instant(at)} is more than ${GENERATED_AT_TOLERANCE_TEXT} later than now (${instant(now)}), so no verification can count yet (OKF 0.3 §5.3) and okfit verify refuses this concept`;
|
|
67
69
|
const blocking = verificationBlockingRestamp((concept.frontmatter.verified ?? []).map((entry) => entry.at), at, now);
|
|
68
70
|
return [{
|
|
69
|
-
message: Option.isSome(blocking) ? `${head}; okfit sync will not re-stamp it, because the verification dated ${instant(blocking.value)} would then count without a re-verification; a human must correct generated.at or that verification` : `${head}; run okfit sync, which re-stamps it`,
|
|
71
|
+
message: Option.isSome(blocking) ? `${head}; okfit sync will not re-stamp it, because the verification dated ${instant(blocking.value)} would then count without a re-verification; a human must correct generated.at or that verification` : `${head}; run okfit sync, which re-stamps it to now (commit any edits to it first)`,
|
|
70
72
|
path: ["generated", "at"]
|
|
71
73
|
}];
|
|
72
74
|
});
|
|
@@ -143,7 +145,21 @@ const nonConceptUnlisted = rule("non-concept-unlisted", (context, severity) => {
|
|
|
143
145
|
});
|
|
144
146
|
return context.bundle.diagnostics.filter((d) => (d.code === "frontmatter-missing" || d.code === "type-missing") && !patterns.some((pattern) => pattern.matches(d.file))).map((d) => diagnostic(d.file, "non-concept-unlisted", severity, globs.length === 0 ? `${d.file} is not a concept (${why(d.code)}) and [bundle] non_concepts is empty, so it allows no non-concept file; add frontmatter with a type, move it out of the bundle, or add a glob that matches it to non_concepts` : `${d.file} is not a concept (${why(d.code)}) and matches no [bundle] non_concepts glob (${globs.join(", ")}); add frontmatter with a type, move it out of the bundle, or list it in non_concepts`, d.range));
|
|
145
147
|
});
|
|
146
|
-
const generatedMissing = perConcept("generated-missing", (concept, context) =>
|
|
148
|
+
const generatedMissing = perConcept("generated-missing", (concept, context) => {
|
|
149
|
+
const agent = context.config.actors?.agent;
|
|
150
|
+
if (agent === void 0) return [];
|
|
151
|
+
const frontmatter = concept.frontmatter;
|
|
152
|
+
if (frontmatter.generated !== void 0) return !Concept.isAbsent(frontmatter.raw.generated) || frontmatter.generated.by !== Generated.LEGACY_BY ? [] : [{
|
|
153
|
+
path: ["timestamp"],
|
|
154
|
+
message: "Concept has no generated block, only a legacy timestamp, which okfit sync cannot convert; replace it with a generated block (generated.by, and generated.at from the timestamp) by hand"
|
|
155
|
+
}];
|
|
156
|
+
const document = Option.getOrUndefined(concept.document.frontmatter);
|
|
157
|
+
if (document !== void 0 && Object.hasOwn(frontmatter.raw, "generated") && !isReplaceableNull(document, "generated")) return [{
|
|
158
|
+
path: ["generated"],
|
|
159
|
+
message: "Concept's generated block has no readable generated.by, so it reads as absent (OKF 0.3 §5.2), and okfit sync cannot fill in a block that is written; set generated.by by hand"
|
|
160
|
+
}];
|
|
161
|
+
return [`Concept has no generated block; okfit sync will create it from actors.agent (${agent}) once the body is committed, or set generated.by by hand`];
|
|
162
|
+
});
|
|
147
163
|
/**
|
|
148
164
|
* OKF 0.3 §10.3: an Attested Computation with neither a `computation` key nor an inline computation is not
|
|
149
165
|
* attestable. `computationBody` is already the bundle's declared reading (fenced block under 0.3, the depth-1
|
|
@@ -310,19 +326,22 @@ const brokenLinks = rule("broken-links", (context, severity) => {
|
|
|
310
326
|
slugCache.set(id, slugs);
|
|
311
327
|
return slugs;
|
|
312
328
|
};
|
|
313
|
-
const check = (file, raw, targetId, target, position) => {
|
|
329
|
+
const check = (file, raw, targetId, target, position, label = "Link target") => {
|
|
314
330
|
const fragment = fragmentOf(raw);
|
|
315
331
|
if (fragment === void 0 || fragment === "") return;
|
|
316
332
|
const slugs = slugsOf(targetId, target);
|
|
317
333
|
if (slugs.includes(fragment)) return;
|
|
318
|
-
const message =
|
|
334
|
+
const message = `${label} "${raw}" exists but has no heading "#${fragment}"; ${candidateHint(fragment, slugs)}`;
|
|
319
335
|
anchors.push(diagnostic(file, "broken-links", severity, message, position));
|
|
320
336
|
};
|
|
321
337
|
for (const link of context.graph.edges) {
|
|
322
|
-
|
|
338
|
+
const { field } = link.data;
|
|
339
|
+
if (link.data.source !== "body" && field === void 0) continue;
|
|
340
|
+
if (field === "superseded_by" && link.to === link.from) continue;
|
|
323
341
|
const target = byId.get(link.to);
|
|
324
342
|
if (target === void 0) continue;
|
|
325
|
-
|
|
343
|
+
const label = field === void 0 ? void 0 : field === "sources.resource" ? "sources[].resource" : field;
|
|
344
|
+
check(fileOf(link.from), link.data.raw, link.to, target, link.data.position, label);
|
|
326
345
|
}
|
|
327
346
|
for (const concept of context.bundle.concepts.values()) for (const link of concept.document.links) {
|
|
328
347
|
if (link.url === void 0 || !link.url.startsWith("#") || link.node.type === "linkReference") continue;
|
|
@@ -346,7 +365,7 @@ const supersededByUnresolved = perConcept("superseded-by-unresolved", (concept,
|
|
|
346
365
|
path: ["superseded_by"]
|
|
347
366
|
}];
|
|
348
367
|
});
|
|
349
|
-
const missingIndex = rule("missing-index", (context, severity) => Derive.indexDirectories(context.bundle).filter((dir) => !context.bundle.indexes.has(dir)).map((dir) => {
|
|
368
|
+
const missingIndex = rule("missing-index", (context, severity) => Derive.indexDirectories(context.bundle).filter((dir) => !context.bundle.indexes.has(dir)).filter((dir) => !context.bundle.files.includes(dir === "" ? "index.md" : `${dir}/index.md`)).filter((dir) => !context.bundle.diagnostics.some((entry) => entry.code === "read-changed" && entry.file === (dir === "" ? "index.md" : `${dir}/index.md`))).map((dir) => {
|
|
350
369
|
const message = `Directory "${dir === "" ? "." : dir}" has no index.md`;
|
|
351
370
|
return diagnostic(dir === "" ? "index.md" : `${dir}/index.md`, "missing-index", severity, message, void 0);
|
|
352
371
|
}));
|
package/internal/reserved.js
CHANGED
|
@@ -4,9 +4,18 @@ import { Diagnostic, DiagnosticRange } from "../Diagnostic.js";
|
|
|
4
4
|
import { IndexDocument, IndexEntry, IndexSection } from "../IndexDocument.js";
|
|
5
5
|
import { LogDocument, LogGroup, LogItem } from "../LogDocument.js";
|
|
6
6
|
import { OkfVersion } from "../OkfVersion.js";
|
|
7
|
+
import { findFrontmatterScalarSource } from "./yamlPathSpan.js";
|
|
7
8
|
|
|
8
9
|
// src/internal/reserved.ts
|
|
9
10
|
/**
|
|
11
|
+
* What an unquoted `okf_version` number says: the text the author wrote (`source`, or what YAML read when the text is
|
|
12
|
+
* unavailable), what YAML read it as (`reads`), and whether the text is a `<major>.<minor>` pair that can be quoted as is.
|
|
13
|
+
*/
|
|
14
|
+
const unquotedMessage = (source, reads, isPair) => {
|
|
15
|
+
const quoteAs = isPair ? source : "<major>.<minor>";
|
|
16
|
+
return source === reads ? `okf_version ${source} is an unquoted number; quote it as "${quoteAs}"` : `okf_version ${source} is an unquoted number, which YAML reads as ${reads}; quote it as "${quoteAs}"`;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
10
19
|
* The one parse configuration every OKF file uses: GFM with frontmatter capture
|
|
11
20
|
* (effected-markdown.md section 1; `Markdown.ts:60-62`).
|
|
12
21
|
*
|
|
@@ -81,9 +90,15 @@ const parseIndex = (input) => {
|
|
|
81
90
|
metadata.okfVersion = version;
|
|
82
91
|
if (Option.isNone(OkfVersion.parse(version))) warn("okf_version", `okf_version "${version}" is not a <major>.<minor> version`);
|
|
83
92
|
}
|
|
93
|
+
} else if (typeof version === "number") {
|
|
94
|
+
const reads = String(version);
|
|
95
|
+
const source = findFrontmatterScalarSource(node, ["okf_version"]) ?? reads;
|
|
96
|
+
const isPair = Option.isSome(OkfVersion.parse(source));
|
|
97
|
+
metadata.okfVersion = source;
|
|
98
|
+
warn("okf_version", unquotedMessage(source, reads, isPair));
|
|
84
99
|
} else if (version !== null && version !== void 0) {
|
|
85
|
-
metadata.okfVersion =
|
|
86
|
-
warn("okf_version",
|
|
100
|
+
metadata.okfVersion = JSON.stringify(version);
|
|
101
|
+
warn("okf_version", "okf_version must be a quoted <major>.<minor> string");
|
|
87
102
|
}
|
|
88
103
|
for (const key of [
|
|
89
104
|
"title",
|
|
@@ -136,7 +151,8 @@ const parseIndex = (input) => {
|
|
|
136
151
|
const fields = {
|
|
137
152
|
path: file,
|
|
138
153
|
dir,
|
|
139
|
-
sections
|
|
154
|
+
sections,
|
|
155
|
+
source: text
|
|
140
156
|
};
|
|
141
157
|
return {
|
|
142
158
|
document: IndexDocument.make({
|
|
@@ -214,7 +230,8 @@ const parseLog = (input) => {
|
|
|
214
230
|
const fields = {
|
|
215
231
|
path: file,
|
|
216
232
|
dir,
|
|
217
|
-
groups
|
|
233
|
+
groups,
|
|
234
|
+
source: text
|
|
218
235
|
};
|
|
219
236
|
return {
|
|
220
237
|
document: LogDocument.make(title === void 0 ? fields : {
|
package/internal/walk.js
CHANGED
package/internal/yamlPathSpan.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { YamlDocument } from "@effected/yaml";
|
|
1
|
+
import { YamlDocument, YamlMap, YamlScalar } from "@effected/yaml";
|
|
2
2
|
import { Option, Result } from "effect";
|
|
3
3
|
import { toFileOffset } from "./position.js";
|
|
4
4
|
|
|
@@ -37,7 +37,10 @@ const frontmatterPathSpan = (text, node, path) => path.length === 0 ? blockSpan(
|
|
|
37
37
|
* The file span of the YAML node at `path`, or `undefined` when there is none (or the re-parse is
|
|
38
38
|
* fatal): {@link frontmatterPathSpan} without its whole-block fallback, for a caller that would
|
|
39
39
|
* rather carry no range than a wrong one. Same quoting rule: a double-quoted scalar's span covers
|
|
40
|
-
* its quotes.
|
|
40
|
+
* its quotes. A bare `key:` has no value node and a tagged empty value (`key: !!null`) has no text
|
|
41
|
+
* (the kit reports a zero-length span just after the tag), so neither has a value span: both answer `undefined`.
|
|
42
|
+
* An edit that splices into the returned span relies on it being the value's own text, so it is never the key's;
|
|
43
|
+
* {@link findFrontmatterAnchorSpan} is the diagnostic reading.
|
|
41
44
|
*
|
|
42
45
|
* @internal
|
|
43
46
|
*/
|
|
@@ -45,10 +48,85 @@ const findFrontmatterPathSpan = (text, node, path) => {
|
|
|
45
48
|
const parsed = parsedYamlOf(node);
|
|
46
49
|
if (Result.isFailure(parsed) || parsed.success.contents === null) return void 0;
|
|
47
50
|
const hit = parsed.success.contents.find(path);
|
|
48
|
-
|
|
51
|
+
if (Option.isNone(hit) || hit.value.length === 0) return void 0;
|
|
52
|
+
return {
|
|
49
53
|
offset: toFileOffset(text, hit.value.offset),
|
|
50
54
|
length: hit.value.length
|
|
51
55
|
};
|
|
52
56
|
};
|
|
57
|
+
/**
|
|
58
|
+
* The source text of the scalar at `path`, as its author wrote it (an unquoted `0.10` reads `"0.10"`, where YAML's
|
|
59
|
+
* value is `0.1`), or `undefined` when the node is not a scalar with text or the re-parse is fatal. Quotes are
|
|
60
|
+
* included for a quoted scalar; a tag or anchor never is.
|
|
61
|
+
*
|
|
62
|
+
* @internal
|
|
63
|
+
*/
|
|
64
|
+
const findFrontmatterScalarSource = (node, path) => {
|
|
65
|
+
const parsed = parsedYamlOf(node);
|
|
66
|
+
if (Result.isFailure(parsed) || parsed.success.contents === null) return void 0;
|
|
67
|
+
const hit = parsed.success.contents.find(path);
|
|
68
|
+
if (Option.isNone(hit) || !(hit.value instanceof YamlScalar)) return void 0;
|
|
69
|
+
const source = hit.value.sourceText(node.value);
|
|
70
|
+
return source === "" ? void 0 : source;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* The file span of the key at `path` (its last segment must be a mapping key), or `undefined` when the key is not
|
|
74
|
+
* written or the re-parse is fatal.
|
|
75
|
+
*
|
|
76
|
+
* @internal
|
|
77
|
+
*/
|
|
78
|
+
const findFrontmatterKeySpan = (text, node, path) => {
|
|
79
|
+
const parsed = parsedYamlOf(node);
|
|
80
|
+
if (Result.isFailure(parsed) || parsed.success.contents === null) return void 0;
|
|
81
|
+
return keySpan(text, parsed.success.contents, path);
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Where a diagnostic about `path` points: the value's own span, or the key's when the value has no text (a bare
|
|
85
|
+
* `key:` or a tagged empty value), or `undefined` when neither exists. For diagnostics only: an edit must not splice
|
|
86
|
+
* into the key, so it uses {@link findFrontmatterPathSpan}.
|
|
87
|
+
*
|
|
88
|
+
* @internal
|
|
89
|
+
*/
|
|
90
|
+
const findFrontmatterAnchorSpan = (text, node, path) => findFrontmatterPathSpan(text, node, path) ?? findFrontmatterKeySpan(text, node, path);
|
|
91
|
+
/**
|
|
92
|
+
* {@link findFrontmatterAnchorSpan} with {@link frontmatterPathSpan}'s whole-block fallback.
|
|
93
|
+
*
|
|
94
|
+
* @internal
|
|
95
|
+
*/
|
|
96
|
+
const frontmatterAnchorSpan = (text, node, path) => path.length === 0 ? blockSpan(node) : findFrontmatterAnchorSpan(text, node, path) ?? blockSpan(node);
|
|
97
|
+
/** The pair of `map` whose key is the plain scalar `key`. */
|
|
98
|
+
const pairOf = (map, key) => map.items.find((item) => item.key instanceof YamlScalar && item.key.value === key);
|
|
99
|
+
const keySpan = (text, contents, path) => {
|
|
100
|
+
const key = path.at(-1);
|
|
101
|
+
if (typeof key !== "string") return void 0;
|
|
102
|
+
const parent = path.length === 1 ? Option.some(contents) : contents.find(path.slice(0, -1));
|
|
103
|
+
if (Option.isNone(parent) || !(parent.value instanceof YamlMap)) return void 0;
|
|
104
|
+
const pair = pairOf(parent.value, key);
|
|
105
|
+
return pair === void 0 ? void 0 : {
|
|
106
|
+
offset: toFileOffset(text, pair.key.offset),
|
|
107
|
+
length: pair.key.length
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* Whether the top-level `key` is a value `okfit sync` can replace whole: unwritten, a bare `key:`, or an untagged,
|
|
112
|
+
* unanchored plain null (`null`, `~`) in a block-style mapping. This mirrors the engine's `locateGeneratedBlock`
|
|
113
|
+
* (`engine/src/verify/locate.ts`), which core cannot import: a tagged or anchored null (`!!null`, `&a ~`) carries
|
|
114
|
+
* syntax a whole-line replace would drop or duplicate, so sync skips it as `generated-unsupported`. A re-parse that
|
|
115
|
+
* fails or a non-mapping document answers `false`, as the engine reports those unsupported too.
|
|
116
|
+
*
|
|
117
|
+
* @internal
|
|
118
|
+
*/
|
|
119
|
+
const isReplaceableNull = (node, key) => {
|
|
120
|
+
const parsed = parsedYamlOf(node);
|
|
121
|
+
if (Result.isFailure(parsed)) return false;
|
|
122
|
+
const contents = parsed.success.contents;
|
|
123
|
+
if (!(contents instanceof YamlMap) || contents.style === "flow") return false;
|
|
124
|
+
const pair = pairOf(contents, key);
|
|
125
|
+
if (pair === void 0) return true;
|
|
126
|
+
const value = pair.value;
|
|
127
|
+
const isNull = value === null || value instanceof YamlScalar && value.style === "plain" && value.value === null && value.tag === void 0 && value.anchor === void 0;
|
|
128
|
+
const lineStart = node.value.lastIndexOf("\n", pair.key.offset - 1) + 1;
|
|
129
|
+
return isNull && node.value.slice(lineStart, pair.key.offset).trim() === "";
|
|
130
|
+
};
|
|
53
131
|
|
|
54
|
-
export { findFrontmatterPathSpan, frontmatterPathSpan };
|
|
132
|
+
export { findFrontmatterAnchorSpan, findFrontmatterKeySpan, findFrontmatterPathSpan, findFrontmatterScalarSource, frontmatterAnchorSpan, frontmatterPathSpan, isReplaceableNull };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@okfit/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Spec-level Open Knowledge Format (OKF) v0.3 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.
|
|
40
|
+
"@effected/config-file": "^0.31.0",
|
|
41
41
|
"@effected/glob": "^0.23.0",
|
|
42
42
|
"@effected/jsonc": "^0.25.0",
|
|
43
|
-
"@effected/markdown": "^0.
|
|
43
|
+
"@effected/markdown": "^0.32.0",
|
|
44
44
|
"@effected/schemastore": "^0.33.0",
|
|
45
45
|
"@effected/source": "^0.5.0",
|
|
46
46
|
"@effected/toml": "^0.20.0",
|
|
47
|
-
"@effected/walker": "^0.
|
|
48
|
-
"@effected/yaml": "^0.
|
|
47
|
+
"@effected/walker": "^0.32.0",
|
|
48
|
+
"@effected/yaml": "^0.31.0",
|
|
49
49
|
"effect": "~4.1.0"
|
|
50
50
|
},
|
|
51
51
|
"engines": {
|