@okfit/core 0.1.0 → 0.2.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/Graph.js ADDED
@@ -0,0 +1,158 @@
1
+ import { DiagnosticRange } from "./Diagnostic.js";
2
+ import { frontmatterFieldSpan, pathFieldsOf, resolvePathField, resolveTarget } from "./internal/links.js";
3
+ import { Graph, Option, Schema } from "effect";
4
+
5
+ //#region src/Graph.ts
6
+ /**
7
+ * Kind of a graph node: a loaded concept, an existing non-concept file (including reserved
8
+ * `index.md`/`log.md`), or a placeholder for a target that does not exist (D-25).
9
+ *
10
+ * @public
11
+ */
12
+ const GraphNodeKind = Schema.Literals([
13
+ "concept",
14
+ "file",
15
+ "missing"
16
+ ]);
17
+ const edgesOf = (concept, lookup) => {
18
+ const out = [];
19
+ const text = concept.document.source;
20
+ for (const ref of pathFieldsOf(concept.frontmatter)) {
21
+ const resolved = resolvePathField(concept.path, ref.field, ref.raw, lookup);
22
+ if (resolved._tag !== "node") continue;
23
+ const span = frontmatterFieldSpan(concept.document, ref.raw);
24
+ const position = span === void 0 ? {} : { position: DiagnosticRange.fromOffset(text, span.offset, span.length) };
25
+ out.push({
26
+ to: resolved.id,
27
+ kind: resolved.kind,
28
+ data: {
29
+ source: "frontmatter",
30
+ field: ref.field,
31
+ raw: ref.raw,
32
+ ...position
33
+ }
34
+ });
35
+ }
36
+ for (const link of concept.document.links) {
37
+ if (link.url === void 0 || link.node.type === "linkReference" || link.node.type === "imageReference") continue;
38
+ const resolved = resolveTarget(concept.path, link.url, lookup);
39
+ if (resolved._tag !== "node") continue;
40
+ const { start, end } = link.node.position;
41
+ const position = DiagnosticRange.fromOffset(text, start.offset, end.offset - start.offset);
42
+ out.push({
43
+ to: resolved.id,
44
+ kind: resolved.kind,
45
+ data: {
46
+ source: "body",
47
+ raw: link.url,
48
+ position
49
+ }
50
+ });
51
+ }
52
+ return out;
53
+ };
54
+ const defaultLabels = {
55
+ nodeLabel: (node) => node.id,
56
+ edgeLabel: (edge) => edge.field ?? ""
57
+ };
58
+ /**
59
+ * The link graph of a bundle over `effect/Graph` (D-26). `graph` is the underlying directed graph for
60
+ * `dfs`, `topo`, `stronglyConnectedComponents`; `index` maps node ids to `NodeIndex`.
61
+ *
62
+ * @public
63
+ */
64
+ var LinkGraph = class LinkGraph {
65
+ graph;
66
+ index;
67
+ nodes;
68
+ edges;
69
+ constructor(graph, index) {
70
+ this.graph = graph;
71
+ this.index = index;
72
+ const byIndex = new Map(Graph.entries(Graph.nodes(graph)));
73
+ this.nodes = [...byIndex.values()];
74
+ this.edges = Array.from(Graph.values(Graph.edges(graph)), (edge) => ({
75
+ from: byIndex.get(edge.source)?.id ?? "",
76
+ to: byIndex.get(edge.target)?.id ?? "",
77
+ data: edge.data
78
+ }));
79
+ }
80
+ /** @internal */
81
+ static _make = (graph, index) => new LinkGraph(graph, index);
82
+ /** The node with `id`, if present. */
83
+ node(id) {
84
+ const at = this.index.get(id);
85
+ return at === void 0 ? Option.none() : Graph.getNode(this.graph, at);
86
+ }
87
+ /** Unique targets of outgoing edges; `[]` for an unknown id. */
88
+ successors(id) {
89
+ return this.neighbours(id, (graph, at) => Graph.successors(graph, at));
90
+ }
91
+ /** Unique sources of incoming edges; `[]` for an unknown id. */
92
+ predecessors(id) {
93
+ return this.neighbours(id, (graph, at) => Graph.predecessors(graph, at));
94
+ }
95
+ /** Edges whose target is a `missing` node; the input of lint `broken-links`. */
96
+ dangling() {
97
+ return this.edges.filter((link) => Option.exists(this.node(link.to), (node) => node.kind === "missing"));
98
+ }
99
+ /** Mermaid flowchart; nodes labelled by id, frontmatter edges by field. */
100
+ toMermaid(options) {
101
+ return Graph.toMermaid(this.graph, {
102
+ ...defaultLabels,
103
+ ...options
104
+ });
105
+ }
106
+ /** GraphViz DOT; same labelling defaults as `toMermaid`. */
107
+ toGraphViz(options) {
108
+ return Graph.toGraphViz(this.graph, {
109
+ ...defaultLabels,
110
+ ...options
111
+ });
112
+ }
113
+ neighbours(id, pick) {
114
+ const at = this.index.get(id);
115
+ if (at === void 0) return [];
116
+ return [...new Set(pick(this.graph, at))].flatMap((next) => Option.toArray(Graph.getNode(this.graph, next)));
117
+ }
118
+ };
119
+ /**
120
+ * Static facade building a {@link LinkGraph} from a loaded bundle (D-6).
121
+ *
122
+ * @public
123
+ */
124
+ var Graph$1 = class {
125
+ constructor() {}
126
+ /**
127
+ * Pure. Body links come from `document.links`, path fields from the frontmatter (D-23, D-24).
128
+ * Placeholder `missing` nodes are added before their edge because `Graph.addEdge` throws on an absent endpoint.
129
+ */
130
+ static fromBundle = (bundle) => {
131
+ const lookup = {
132
+ files: new Set(bundle.files),
133
+ concepts: new Set(bundle.concepts.keys())
134
+ };
135
+ const index = /* @__PURE__ */ new Map();
136
+ const graph = Graph.directed((mutable) => {
137
+ const node = (id, kind) => {
138
+ const found = index.get(id);
139
+ if (found !== void 0) return found;
140
+ const created = Graph.addNode(mutable, {
141
+ id,
142
+ kind
143
+ });
144
+ index.set(id, created);
145
+ return created;
146
+ };
147
+ for (const id of bundle.concepts.keys()) node(id, "concept");
148
+ for (const [id, concept] of bundle.concepts) {
149
+ const from = node(id, "concept");
150
+ for (const edge of edgesOf(concept, lookup)) Graph.addEdge(mutable, from, node(edge.to, edge.kind), edge.data);
151
+ }
152
+ });
153
+ return LinkGraph._make(graph, index);
154
+ };
155
+ };
156
+
157
+ //#endregion
158
+ export { Graph$1 as Graph, GraphNodeKind, LinkGraph };
@@ -0,0 +1,30 @@
1
+ import { DiagnosticRange } from "./Diagnostic.js";
2
+ import { Schema } from "effect";
3
+
4
+ //#region src/IndexDocument.ts
5
+ /** One `index.md` list item. @public */
6
+ var IndexEntry = class extends Schema.Class("IndexEntry")({
7
+ title: Schema.String,
8
+ target: Schema.String,
9
+ description: Schema.optionalKey(Schema.String),
10
+ range: DiagnosticRange
11
+ }) {};
12
+ /** One `index.md` H1 section. @public */
13
+ var IndexSection = class extends Schema.Class("IndexSection")({
14
+ heading: Schema.String,
15
+ entries: Schema.Array(IndexEntry),
16
+ range: DiagnosticRange
17
+ }) {};
18
+ /**
19
+ * A parsed `index.md` (D-21). `okfVersion` is present only on the bundle root.
20
+ * @public
21
+ */
22
+ var IndexDocument = class extends Schema.Class("IndexDocument")({
23
+ path: Schema.String,
24
+ dir: Schema.String,
25
+ okfVersion: Schema.optionalKey(Schema.String),
26
+ sections: Schema.Array(IndexSection)
27
+ }) {};
28
+
29
+ //#endregion
30
+ export { IndexDocument, IndexEntry, IndexSection };
package/LogDocument.js ADDED
@@ -0,0 +1,28 @@
1
+ import { DiagnosticRange } from "./Diagnostic.js";
2
+ import { Schema } from "effect";
3
+
4
+ //#region src/LogDocument.ts
5
+ /** One `log.md` list item. @public */
6
+ var LogItem = class extends Schema.Class("LogItem")({
7
+ text: Schema.String,
8
+ range: DiagnosticRange
9
+ }) {};
10
+ /** One `log.md` `## YYYY-MM-DD` group. @public */
11
+ var LogGroup = class extends Schema.Class("LogGroup")({
12
+ date: Schema.String,
13
+ items: Schema.Array(LogItem),
14
+ range: DiagnosticRange
15
+ }) {};
16
+ /**
17
+ * A parsed `log.md` (D-21).
18
+ * @public
19
+ */
20
+ var LogDocument = class extends Schema.Class("LogDocument")({
21
+ path: Schema.String,
22
+ dir: Schema.String,
23
+ title: Schema.optionalKey(Schema.String),
24
+ groups: Schema.Array(LogGroup)
25
+ }) {};
26
+
27
+ //#endregion
28
+ export { LogDocument, LogGroup, LogItem };
package/OkfitConfig.js ADDED
@@ -0,0 +1,471 @@
1
+ import { Actor } from "./Actor.js";
2
+ import { Duration, Effect, Option, Schema, SchemaGetter, SchemaIssue, SchemaTransformation } from "effect";
3
+ import { ConfigFile, TomlCodec } from "@effected/config-file";
4
+
5
+ //#region src/OkfitConfig.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
+ const SHORT_DURATION_RE = /^(\d+)(h|d|w)$/;
28
+ const LONG_DURATION_RE = /^\d+(?:\.\d+)?\s+(?:nanos?|micros?|millis?|seconds?|minutes?|hours?|days?|weeks?)$/;
29
+ const STALE_AFTER_PATTERN_RE = /^(?:\d+[hdw]|\d+(?:\.\d+)?\s+(?:nanos?|micros?|millis?|seconds?|minutes?|hours?|days?|weeks?))$/;
30
+ const HOUR_MILLIS = 36e5;
31
+ const DAY_MILLIS = 864e5;
32
+ const WEEK_MILLIS = 6048e5;
33
+ const parseStaleAfter = (input) => {
34
+ const short = SHORT_DURATION_RE.exec(input);
35
+ if (short !== null) {
36
+ const amount = Number(short[1]);
37
+ switch (short[2]) {
38
+ case "h": return Option.some(Duration.hours(amount));
39
+ case "d": return Option.some(Duration.days(amount));
40
+ default: return Option.some(Duration.weeks(amount));
41
+ }
42
+ }
43
+ if (LONG_DURATION_RE.test(input)) return Duration.fromInput(input);
44
+ return Option.none();
45
+ };
46
+ const formatStaleAfter = (duration) => {
47
+ const millis = Duration.toMillis(duration);
48
+ if (Number.isInteger(millis) && millis >= 0) {
49
+ if (millis !== 0 && millis % WEEK_MILLIS === 0) return `${millis / WEEK_MILLIS}w`;
50
+ if (millis % DAY_MILLIS === 0) return `${millis / DAY_MILLIS}d`;
51
+ if (millis % HOUR_MILLIS === 0) return `${millis / HOUR_MILLIS}h`;
52
+ }
53
+ return `${millis} millis`;
54
+ };
55
+ /**
56
+ * `lifecycle.default_stale_after` codec: `^(\d+)(h|d|w)$` or Effect's
57
+ * `"<n> <unit>"` form decodes to a `Duration` (D-30). Encoding emits the
58
+ * shortest exact `w`/`d`/`h` spelling, otherwise `"<n> millis"`.
59
+ *
60
+ * @remarks
61
+ * `@effected/toml` has no duration syntax and `Schema.DurationFromString`
62
+ * rejects `"90d"`, so this is core's own codec (effected-yaml-toml-config-file-app.md §2).
63
+ *
64
+ * @public
65
+ */
66
+ const StaleAfterDuration = Schema.annotateEncoded({
67
+ title: "Stale-after duration",
68
+ description: "How long a concept may go unedited before lint `stale` fires. Accepts \"<n>h\", \"<n>d\", \"<n>w\", or Effect's \"<n> <unit>\" long form.",
69
+ default: "90d",
70
+ examples: [
71
+ "90d",
72
+ "2w",
73
+ "12h"
74
+ ]
75
+ })(Schema.String.pipe(Schema.check(Schema.isPattern(STALE_AFTER_PATTERN_RE, { message: "expected \"<n>h\", \"<n>d\", \"<n>w\" or \"<n> <unit>\"" })), Schema.decodeTo(Schema.Duration, {
76
+ decode: SchemaGetter.transformOrFail((input, options) => Option.match(parseStaleAfter(input), {
77
+ onNone: () => Effect.fail(new SchemaIssue.InvalidValue({ message: `expected "<n>h", "<n>d", "<n>w" or "<n> <unit>", got ${JSON.stringify(input)}` }, input, options)),
78
+ onSome: Effect.succeed
79
+ })),
80
+ encode: SchemaGetter.transform(formatStaleAfter)
81
+ })));
82
+ /**
83
+ * A `types.<Name>.fields.<key>` declaration (spec 4.2): a description plus
84
+ * either an enum of values with descriptions or `kind = "path"`.
85
+ * @public
86
+ */
87
+ const FieldDeclaration = Schema.Struct({
88
+ description: Schema.String.annotate({ description: "What this extension field means." }),
89
+ values: Schema.optionalKey(Schema.Record(Schema.String, Schema.String).annotate({ description: "The allowed values, each with a one-sentence description." })),
90
+ kind: Schema.optionalKey(Schema.Literal("path").annotate({
91
+ description: "\"path\": the value is a concept id or file path, not one of an enumerated set.",
92
+ examples: ["path"]
93
+ }))
94
+ }).annotate({
95
+ title: "Extension field",
96
+ description: "One `[types.<Name>.fields.<key>]` declaration."
97
+ });
98
+ /**
99
+ * A `types.<Name>` declaration (spec 4.2).
100
+ * @public
101
+ */
102
+ const TypeDeclaration = Schema.Struct({
103
+ description: Schema.optionalKey(Schema.String.annotate({ description: "One-sentence summary of what this type represents." })),
104
+ guidance: Schema.optionalKey(Schema.String.annotate({ description: "Longer guidance shown to an authoring agent or human writing a concept of this type." })),
105
+ required: Schema.optionalKey(Schema.Array(Schema.String).annotate({ description: "Frontmatter keys a concept of this type must carry, beyond `concepts.required`." })),
106
+ require_verified: Schema.optionalKey(Schema.Boolean.annotate({
107
+ description: "Whether a concept of this type must carry a `verified` entry to satisfy lint `require-verified-unmet`.",
108
+ default: false
109
+ })),
110
+ fields: Schema.optionalKey(Schema.Record(Schema.String, FieldDeclaration).annotate({ description: "Extension fields this type's frontmatter may declare." }))
111
+ }).annotate({
112
+ title: "Concept type",
113
+ description: "One `[types.<Name>]` declaration."
114
+ });
115
+ /**
116
+ * A `tags.<name>` declaration (spec 4.2).
117
+ * @public
118
+ */
119
+ const TagDeclaration = Schema.Struct({ description: Schema.optionalKey(Schema.String.annotate({ description: "One-sentence summary of what applying this tag means." })) }).annotate({
120
+ title: "Tag",
121
+ description: "One `[tags.<name>]` declaration."
122
+ });
123
+ /**
124
+ * The `[lint]` table: one optional `LintLevel` per lint code, snake_case (D-34).
125
+ * @public
126
+ */
127
+ const LintTable = Schema.Struct({
128
+ broken_links: Schema.optionalKey(LintLevel.annotate({
129
+ title: "broken-links",
130
+ description: "A link in a concept's body or frontmatter does not resolve. Default \"warn\".",
131
+ default: "warn"
132
+ })),
133
+ missing_index: Schema.optionalKey(LintLevel.annotate({
134
+ title: "missing-index",
135
+ description: "A concept-holding directory has no index.md. Default \"warn\".",
136
+ default: "warn"
137
+ })),
138
+ unknown_type: Schema.optionalKey(LintLevel.annotate({
139
+ title: "unknown-type",
140
+ description: "A concept's type is not one of the config's declared [types.<Name>]. Default \"error\", off when no types are declared.",
141
+ default: "error"
142
+ })),
143
+ required_key_missing: Schema.optionalKey(LintLevel.annotate({
144
+ title: "required-key-missing",
145
+ description: "A concept is missing a frontmatter key its type or concepts.required requires. Default \"error\".",
146
+ default: "error"
147
+ })),
148
+ field_value_unknown: Schema.optionalKey(LintLevel.annotate({
149
+ title: "field-value-unknown",
150
+ description: "A frontmatter field's value is not one of its declared values. Default \"error\".",
151
+ default: "error"
152
+ })),
153
+ require_verified_unmet: Schema.optionalKey(LintLevel.annotate({
154
+ title: "require-verified-unmet",
155
+ description: "A concept whose type sets require_verified = true carries no verified entry. Default \"error\".",
156
+ default: "error"
157
+ })),
158
+ family_invalid: Schema.optionalKey(LintLevel.annotate({
159
+ title: "family-invalid",
160
+ description: "A concept's declared family does not match an accepted shape. Default \"error\".",
161
+ default: "error"
162
+ })),
163
+ computation_runtime_missing: Schema.optionalKey(LintLevel.annotate({
164
+ title: "computation-runtime-missing",
165
+ description: "A referenced computation's runtime is not available. Default \"error\".",
166
+ default: "error"
167
+ })),
168
+ footnote_source_unknown: Schema.optionalKey(LintLevel.annotate({
169
+ title: "footnote-source-unknown",
170
+ description: "A footnote's source does not resolve. Default \"warn\".",
171
+ default: "warn"
172
+ })),
173
+ log_frontmatter: Schema.optionalKey(LintLevel.annotate({
174
+ title: "log-frontmatter",
175
+ description: "log.md carries frontmatter, which the spec reserves against. Default \"warn\".",
176
+ default: "warn"
177
+ })),
178
+ actor_prefix_unknown: Schema.optionalKey(LintLevel.annotate({
179
+ title: "actor-prefix-unknown",
180
+ description: "An actor's prefix is not human, process, or a producer shape. Default \"info\".",
181
+ default: "info"
182
+ })),
183
+ legacy_timestamp: Schema.optionalKey(LintLevel.annotate({
184
+ title: "legacy-timestamp",
185
+ description: "A concept uses the legacy timestamp field instead of generated.at. Default \"info\".",
186
+ default: "info"
187
+ })),
188
+ config_unknown_key: Schema.optionalKey(LintLevel.annotate({
189
+ title: "config-unknown-key",
190
+ description: "The config file declares a top-level key the schema does not recognize. Default \"warn\".",
191
+ default: "warn"
192
+ })),
193
+ stale: Schema.optionalKey(LintLevel.annotate({
194
+ title: "stale",
195
+ description: "A concept has gone unedited past lifecycle.default_stale_after. Default \"info\".",
196
+ default: "info"
197
+ })),
198
+ walk_unreadable: Schema.optionalKey(LintLevel.annotate({
199
+ title: "walk-unreadable",
200
+ description: "A directory in the bundle could not be read while walking. Default \"warn\".",
201
+ default: "warn"
202
+ })),
203
+ generated_at_drift: Schema.optionalKey(LintLevel.annotate({
204
+ title: "generated-at-drift",
205
+ description: "A committed concept's generated.at is missing or does not match its last body-changing commit. Default \"info\".",
206
+ default: "info"
207
+ }))
208
+ }).annotate({
209
+ title: "Lint severities",
210
+ description: "Per-code severity overrides. Any key omitted keeps its default."
211
+ });
212
+ /**
213
+ * The `OkfitConfig` struct schema. Exported only so the `OkfitConfigFields`
214
+ * type below is reachable from the rollup; the barrel never re-exports this
215
+ * value, so it stays out of the named public surface.
216
+ * @public
217
+ */
218
+ const okfitConfigFields = Schema.Struct({
219
+ okf_version: Schema.optionalKey(Schema.String.annotate({
220
+ title: "OKF spec version",
221
+ description: "The Open Knowledge Format spec version this bundle targets.",
222
+ default: "0.2",
223
+ examples: ["0.2"]
224
+ })),
225
+ bundle: Schema.optionalKey(Schema.Struct({
226
+ path: Schema.optionalKey(Schema.String.annotate({
227
+ title: "Bundle directory",
228
+ description: "The OKF bundle's root directory, relative to the project root.",
229
+ default: "okf",
230
+ examples: ["okf"]
231
+ })),
232
+ profile: Schema.optionalKey(Schema.String.annotate({
233
+ title: "Profile name",
234
+ description: "The named profile merged under `DEFAULTS < profile < file`, or \"none\" to disable profile merging.",
235
+ default: "software-project",
236
+ examples: ["software-project", "none"]
237
+ }))
238
+ }).annotate({
239
+ title: "Bundle location and profile",
240
+ description: "Where the OKF bundle lives and which profile merges under it."
241
+ })),
242
+ concepts: Schema.optionalKey(Schema.Struct({
243
+ required: Schema.optionalKey(Schema.Array(Schema.String).annotate({
244
+ title: "Required frontmatter keys",
245
+ description: "Frontmatter keys every concept must carry, beyond the spec's required set.",
246
+ default: []
247
+ })),
248
+ tags: Schema.optionalKey(Schema.Struct({ required: Schema.optionalKey(Schema.Array(Schema.String).annotate({
249
+ title: "Required tags",
250
+ description: "Tags every concept must carry.",
251
+ default: []
252
+ })) }))
253
+ }).annotate({
254
+ title: "Concept-level requirements",
255
+ description: "Requirements every concept in the bundle must satisfy, beyond the spec's own."
256
+ })),
257
+ lifecycle: Schema.optionalKey(Schema.Struct({ default_stale_after: Schema.optionalKey(StaleAfterDuration) }).annotate({
258
+ title: "Concept lifecycle",
259
+ description: "Staleness policy for the bundle."
260
+ })),
261
+ actors: Schema.optionalKey(Schema.Struct({
262
+ agent: Schema.optionalKey(Actor.annotate({
263
+ title: "Agent actor",
264
+ description: "The actor id an agent writes as `generated.by`."
265
+ })),
266
+ humans: Schema.optionalKey(Schema.Array(Actor).annotate({
267
+ title: "Human actors",
268
+ description: "Actor ids for the humans working in this bundle, \"human:<id>\" form.",
269
+ default: [],
270
+ examples: [["human:spencer"]]
271
+ }))
272
+ }).annotate({
273
+ title: "Actor identities",
274
+ description: "Who authors and verifies concepts in this bundle."
275
+ })),
276
+ lint: Schema.optionalKey(LintTable),
277
+ types: Schema.optionalKey(Schema.Record(Schema.String, TypeDeclaration).annotate({
278
+ title: "Concept type declarations",
279
+ description: "One entry per concept type, keyed by type name."
280
+ })),
281
+ tags: Schema.optionalKey(Schema.Record(Schema.String, TagDeclaration).annotate({
282
+ title: "Tag declarations",
283
+ description: "One entry per tag, keyed by tag name."
284
+ })),
285
+ extensions: Schema.Record(Schema.String, Schema.Unknown)
286
+ });
287
+ /**
288
+ * The schema the published JSON Schema document is generated from (C-15):
289
+ * `okfitConfigFields` minus `extensions` (wire bookkeeping no human writes),
290
+ * with an open rest so unknown top-level keys are permitted at the root while
291
+ * every declared table stays closed (C-16, D-31).
292
+ *
293
+ * @public
294
+ */
295
+ const okfitConfigDocumentFields = Schema.StructWithRest(Schema.Struct({
296
+ okf_version: okfitConfigFields.fields.okf_version,
297
+ bundle: okfitConfigFields.fields.bundle,
298
+ concepts: okfitConfigFields.fields.concepts,
299
+ lifecycle: okfitConfigFields.fields.lifecycle,
300
+ actors: okfitConfigFields.fields.actors,
301
+ lint: okfitConfigFields.fields.lint,
302
+ types: okfitConfigFields.fields.types,
303
+ tags: okfitConfigFields.fields.tags
304
+ }), [Schema.Record(Schema.String, Schema.Unknown)]).annotate({
305
+ title: "okfit config",
306
+ description: "okfit's TOML config file (OKF spec 4.2). Unrecognized top-level keys are preserved verbatim and produce a config-unknown-key warning, never a validation error.\nhttps://github.com/spencerbeggs/okfit#configuration",
307
+ "x-tombi-toml-version": "v1.1.0"
308
+ });
309
+ const RawTable = Schema.Record(Schema.String, Schema.Unknown);
310
+ const KNOWN_KEYS = new Set(Object.keys(okfitConfigFields.fields).filter((key) => key !== "extensions"));
311
+ const OkfitConfigWire = RawTable.pipe(Schema.decodeTo(okfitConfigFields, SchemaTransformation.transform({
312
+ decode: (raw) => {
313
+ const known = {};
314
+ const extensions = Object.create(null);
315
+ for (const [key, value] of Object.entries(raw)) if (KNOWN_KEYS.has(key)) known[key] = value;
316
+ else extensions[key] = value;
317
+ return {
318
+ ...known,
319
+ extensions
320
+ };
321
+ },
322
+ encode: (encoded) => {
323
+ const { extensions, ...known } = encoded;
324
+ return {
325
+ ...extensions,
326
+ ...known
327
+ };
328
+ }
329
+ })));
330
+ const FORBIDDEN_KEYS = /* @__PURE__ */ new Set([
331
+ "__proto__",
332
+ "constructor",
333
+ "prototype"
334
+ ]);
335
+ const isPlainObject = (value) => {
336
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
337
+ const proto = Object.getPrototypeOf(value);
338
+ return proto === Object.prototype || proto === null;
339
+ };
340
+ const define = (target, key, value) => {
341
+ Object.defineProperty(target, key, {
342
+ value,
343
+ writable: true,
344
+ enumerable: true,
345
+ configurable: true
346
+ });
347
+ };
348
+ const mergeRecords = (base, override) => {
349
+ const result = {};
350
+ for (const key of Object.keys(base)) if (!FORBIDDEN_KEYS.has(key)) define(result, key, base[key]);
351
+ for (const key of Object.keys(override)) {
352
+ if (FORBIDDEN_KEYS.has(key)) continue;
353
+ const incoming = override[key];
354
+ const current = result[key];
355
+ if (Object.hasOwn(result, key) && isPlainObject(current) && isPlainObject(incoming)) define(result, key, mergeRecords(current, incoming));
356
+ else define(result, key, incoming);
357
+ }
358
+ return result;
359
+ };
360
+ const merge = (base, override) => mergeRecords(base, override);
361
+ const LINT_KEY = {
362
+ "broken-links": "broken_links",
363
+ "missing-index": "missing_index",
364
+ "unknown-type": "unknown_type",
365
+ "required-key-missing": "required_key_missing",
366
+ "field-value-unknown": "field_value_unknown",
367
+ "require-verified-unmet": "require_verified_unmet",
368
+ "family-invalid": "family_invalid",
369
+ "computation-runtime-missing": "computation_runtime_missing",
370
+ "footnote-source-unknown": "footnote_source_unknown",
371
+ "log-frontmatter": "log_frontmatter",
372
+ "actor-prefix-unknown": "actor_prefix_unknown",
373
+ "legacy-timestamp": "legacy_timestamp",
374
+ "config-unknown-key": "config_unknown_key",
375
+ stale: "stale",
376
+ "walk-unreadable": "walk_unreadable",
377
+ "generated-at-drift": "generated_at_drift"
378
+ };
379
+ const DEFAULT_LINT = {
380
+ broken_links: "warn",
381
+ missing_index: "warn",
382
+ unknown_type: "error",
383
+ required_key_missing: "error",
384
+ field_value_unknown: "error",
385
+ require_verified_unmet: "error",
386
+ family_invalid: "error",
387
+ computation_runtime_missing: "error",
388
+ footnote_source_unknown: "warn",
389
+ log_frontmatter: "warn",
390
+ actor_prefix_unknown: "info",
391
+ legacy_timestamp: "info",
392
+ config_unknown_key: "warn",
393
+ stale: "info",
394
+ walk_unreadable: "warn",
395
+ generated_at_drift: "info"
396
+ };
397
+ const toSeverity = (level) => level === "warn" ? "warning" : level;
398
+ const severityFor = (config, code) => {
399
+ if (code === "unknown-type" && Object.keys(config.types ?? {}).length === 0) return "off";
400
+ const key = LINT_KEY[code];
401
+ return toSeverity(config.lint?.[key] ?? DEFAULT_LINT[key]);
402
+ };
403
+ /** Recursively freezes plain objects and arrays in place; leaves other values (class instances) untouched. */
404
+ const deepFreeze = (value) => {
405
+ if (Array.isArray(value)) {
406
+ for (const item of value) deepFreeze(item);
407
+ return Object.freeze(value);
408
+ }
409
+ if (value !== null && typeof value === "object" && Object.getPrototypeOf(value) === Object.prototype) {
410
+ for (const key of Object.keys(value)) deepFreeze(value[key]);
411
+ return Object.freeze(value);
412
+ }
413
+ return value;
414
+ };
415
+ const DEFAULTS = deepFreeze({
416
+ okf_version: "0.2",
417
+ bundle: {
418
+ path: "okf",
419
+ profile: "software-project"
420
+ },
421
+ concepts: {
422
+ required: [],
423
+ tags: { required: [] }
424
+ },
425
+ lifecycle: { default_stale_after: Duration.days(90) },
426
+ actors: { humans: [] },
427
+ lint: { ...DEFAULT_LINT },
428
+ types: {},
429
+ tags: {},
430
+ extensions: {}
431
+ });
432
+ const read = (path) => ConfigFile.read(path, {
433
+ schema: OkfitConfigWire,
434
+ codec: TomlCodec
435
+ }).pipe(Effect.withSpan("OkfitConfig.read", { attributes: { path } }));
436
+ /**
437
+ * The okfit config codec and its statics (spec 4.2, D-28 to D-31).
438
+ *
439
+ * @remarks
440
+ * Decodes a parsed TOML table to a plain `OkfitConfig`, keeping unknown
441
+ * top-level keys in `extensions`; encoding flattens them back so the on-disk
442
+ * shape never carries a literal `extensions` key. `merge` is pure: plain
443
+ * objects deep-merge, arrays and scalars in `override` replace wholesale. The
444
+ * intended order is `DEFAULTS < profile < file`, applied by the caller (the
445
+ * CLI resolves the profile; core cannot import `@okfit/profiles`).
446
+ *
447
+ * @public
448
+ */
449
+ const OkfitConfig = Object.assign(OkfitConfigWire, {
450
+ fields: okfitConfigFields.fields,
451
+ DEFAULTS,
452
+ merge,
453
+ severityFor,
454
+ read
455
+ });
456
+ /**
457
+ * The only service in core: the config-file service tag for okfit's TOML
458
+ * config (D-7). Core exports the tag so `@okfit/cli` and `@okfit/mcp` share
459
+ * one identity; the layer (`ConfigFile.layer` with the spec 4.1 resolvers and
460
+ * XDG fallback) is built by the CLI, never here (D-29).
461
+ *
462
+ * @remarks
463
+ * Shape is `ConfigFileShape<OkfitConfig>`: `load`, `loadFrom`, `discover`,
464
+ * `loadOrDefault`, `validate`, `write(value, path)` (used by `okfit init`), `save`, `update`.
465
+ *
466
+ * @public
467
+ */
468
+ var OkfitConfigFile = class extends ConfigFile.Service()("@okfit/core/OkfitConfigFile") {};
469
+
470
+ //#endregion
471
+ export { FieldDeclaration, LintLevel, LintTable, OkfitConfig, OkfitConfigFile, StaleAfterDuration, TagDeclaration, TypeDeclaration, okfitConfigDocumentFields, okfitConfigFields };