@okfit/core 0.16.0 → 0.17.1

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/OkfitConfig.js CHANGED
@@ -1,34 +1,15 @@
1
1
  import { ConfigFile, ConfigMerge } from "@effected/config-file";
2
2
  import { TomlCodec } from "@effected/config-file/toml";
3
+ import { GitRef } from "@effected/git";
3
4
  import { GlobPattern } from "@effected/glob";
4
5
  import { HostedSchema } from "@effected/schemastore";
5
6
  import { Duration, Effect, Option, Result, Schema, SchemaGetter, SchemaIssue, SchemaTransformation } from "effect";
6
7
  import { Actor, ActorPattern } from "./Actor.js";
7
- import { GENERATED_AT_TOLERANCE_TEXT } from "./GeneratedAtFuture.js";
8
- import { INTEGRITY_KEY, OKFIT_KEY_PREFIX } from "./Integrity.js";
8
+ import { LintLevel, LintTable } from "./LintTable.js";
9
+ import { Reference } from "./Reference.js";
10
+ import { RepoIdentity } from "./RepoIdentity.js";
9
11
 
10
12
  // src/OkfitConfig.ts
11
- /**
12
- * Severity a lint rule is configured to. `"info"` extends spec 4.2's
13
- * `off | warn | error` so the D-34 `info` defaults are expressible.
14
- *
15
- * @public
16
- */
17
- const LintLevel = Schema.Literals([
18
- "off",
19
- "info",
20
- "warn",
21
- "error"
22
- ]).annotate({
23
- title: "Lint severity",
24
- description: "off — never reported; info, warn, error — the diagnostic's rendered severity.",
25
- "x-taplo": { docs: { enumValues: [
26
- "Never reported.",
27
- "Reported as information.",
28
- "Reported as a warning.",
29
- "Reported as an error."
30
- ] } }
31
- });
32
13
  const SHORT_DURATION_RE = /^(\d+)(h|d|w)$/;
33
14
  const LONG_DURATION_RE = /^\d+(?:\.\d+)?\s+(?:nanos?|micros?|millis?|seconds?|minutes?|hours?|days?|weeks?)$/;
34
15
  const STALE_AFTER_PATTERN_RE = /^(?:\d+[hdw]|\d+(?:\.\d+)?\s+(?:nanos?|micros?|millis?|seconds?|minutes?|hours?|days?|weeks?))$/u;
@@ -126,235 +107,6 @@ const TagDeclaration = Schema.Struct({ description: Schema.optionalKey(Schema.St
126
107
  description: "One `[tags.<name>]` declaration."
127
108
  });
128
109
  /**
129
- * The `[lint]` table: one optional `LintLevel` per lint code, snake_case (D-34).
130
- * @public
131
- */
132
- const LintTable = Schema.Struct({
133
- broken_links: Schema.optionalKey(LintLevel.annotate({
134
- title: "broken-links",
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\".",
136
- default: "warn"
137
- })),
138
- missing_index: Schema.optionalKey(LintLevel.annotate({
139
- title: "missing-index",
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\".",
141
- default: "warn"
142
- })),
143
- unknown_type: Schema.optionalKey(LintLevel.annotate({
144
- title: "unknown-type",
145
- description: "A concept's type is not one of the config's declared [types.<Name>]. Default \"error\", off when no types are declared.",
146
- default: "error"
147
- })),
148
- required_key_missing: Schema.optionalKey(LintLevel.annotate({
149
- title: "required-key-missing",
150
- description: "A concept is missing a frontmatter key its type or concepts.required requires. Default \"error\".",
151
- default: "error"
152
- })),
153
- field_value_unknown: Schema.optionalKey(LintLevel.annotate({
154
- title: "field-value-unknown",
155
- description: "A frontmatter field's value is not one of its declared values. Default \"error\".",
156
- default: "error"
157
- })),
158
- require_verified_unmet: Schema.optionalKey(LintLevel.annotate({
159
- title: "require-verified-unmet",
160
- description: "A concept whose type sets require_verified = true carries no verified entry and is not a draft. Default \"error\".",
161
- default: "error"
162
- })),
163
- verified_before_change: Schema.optionalKey(LintLevel.annotate({
164
- title: "verified-before-change",
165
- description: "A concept has verification events, but the ones at or after generated.at give a lower trust tier than all of them would: the content changed after it was verified (OKF 0.3 §5.3, \"verified before the last change\"). Draft, deprecated and unknown-status concepts are exempt. Default \"warn\".",
166
- default: "warn"
167
- })),
168
- family_invalid: Schema.optionalKey(LintLevel.annotate({
169
- title: "family-invalid",
170
- description: `okfit's own ${INTEGRITY_KEY} family does not match its shape. Default "error".`,
171
- default: "error"
172
- })),
173
- computation_runtime_missing: Schema.optionalKey(LintLevel.annotate({
174
- title: "computation-runtime-missing",
175
- description: "A referenced computation's runtime is not available. Default \"error\".",
176
- default: "error"
177
- })),
178
- footnote_source_unknown: Schema.optionalKey(LintLevel.annotate({
179
- title: "footnote-source-unknown",
180
- description: "A footnote's source does not resolve. Default \"warn\".",
181
- default: "warn"
182
- })),
183
- footnote_undefined: Schema.optionalKey(LintLevel.annotate({
184
- title: "footnote-undefined",
185
- description: "A footnote reference has no matching definition line in the body. Default \"warn\".",
186
- default: "warn"
187
- })),
188
- log_frontmatter: Schema.optionalKey(LintLevel.annotate({
189
- title: "log-frontmatter",
190
- description: "log.md carries frontmatter, which the spec reserves against. Default \"warn\".",
191
- default: "warn"
192
- })),
193
- actor_prefix_unknown: Schema.optionalKey(LintLevel.annotate({
194
- title: "actor-prefix-unknown",
195
- description: "An actor in generated.by, verified[].by or sources[].author uses a scheme other than human, team, process or a producer shape; it is accepted and read as non-human. Default \"info\".",
196
- default: "info"
197
- })),
198
- actor_email: Schema.optionalKey(LintLevel.annotate({
199
- title: "actor-email",
200
- description: `An actor in generated.by, verified[].by, ${INTEGRITY_KEY}.verified.by or [actors].humans contains "@", so an email address or domain is stored in the bundle or its config. Use a human:<id> without the domain. Default "warn".`,
201
- default: "warn"
202
- })),
203
- verified_actor_unknown: Schema.optionalKey(LintLevel.annotate({
204
- title: "verified-actor-unknown",
205
- description: `A human verified[].by or ${INTEGRITY_KEY}.verified.by matches no entry of a non-empty [actors].humans. Silent when the list is empty. Default "warn".`,
206
- default: "warn"
207
- })),
208
- legacy_timestamp: Schema.optionalKey(LintLevel.annotate({
209
- title: "legacy-timestamp",
210
- description: "A concept uses the legacy timestamp field instead of generated.at. Default \"info\".",
211
- default: "info"
212
- })),
213
- config_unknown_key: Schema.optionalKey(LintLevel.annotate({
214
- title: "config-unknown-key",
215
- description: "The config file declares a top-level key the schema does not recognize. Default \"warn\".",
216
- default: "warn"
217
- })),
218
- config_okf_version_stale: Schema.optionalKey(LintLevel.annotate({
219
- title: "config-okf-version-stale",
220
- description: "The config sets okf_version and the bundle-root index.md declares a different one; the index decides how the bundle reads, so the config value is stale. Default \"warn\".",
221
- default: "warn"
222
- })),
223
- stale: Schema.optionalKey(LintLevel.annotate({
224
- title: "stale",
225
- description: "A concept is past its stale_after instant. Default \"info\".",
226
- default: "info"
227
- })),
228
- walk_unreadable: Schema.optionalKey(LintLevel.annotate({
229
- title: "walk-unreadable",
230
- description: "A directory in the bundle could not be read while walking. Default \"warn\".",
231
- default: "warn"
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
- })),
238
- frontmatter_missing: Schema.optionalKey(LintLevel.annotate({
239
- title: "frontmatter-missing",
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
- default: "warn"
242
- })),
243
- type_missing: Schema.optionalKey(LintLevel.annotate({
244
- title: "type-missing",
245
- description: "A .md file's frontmatter has no non-empty string type, so it is not a concept and is skipped (OKF 0.3 §3.2). Default \"warn\".",
246
- default: "warn"
247
- })),
248
- symlink_escape: Schema.optionalKey(LintLevel.annotate({
249
- title: "symlink-escape",
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\".",
251
- default: "warn"
252
- })),
253
- generated_at_drift: Schema.optionalKey(LintLevel.annotate({
254
- title: "generated-at-drift",
255
- description: "A committed concept's generated.at is missing or does not match its last body-changing commit, and is not otherwise authoritative (issue #19: a stamp recorded during the unchanged-body run survives a squash/rebase merge). Default \"warn\".",
256
- default: "warn"
257
- })),
258
- verified_drift: Schema.optionalKey(LintLevel.annotate({
259
- title: "verified-drift",
260
- description: `A concept's latest human verification no longer covers its current content: the body or authored frontmatter changed since, the binding (${INTEGRITY_KEY}.verified) is missing, a later human entry is unbound, or the bound verifier is not in a non-empty [actors].humans. Draft and deprecated concepts are exempt, since okfit verify refuses them. A signal to re-verify, not a gate. Default "warn".`,
261
- default: "warn"
262
- })),
263
- status_missing: Schema.optionalKey(LintLevel.annotate({
264
- title: "status-missing",
265
- description: "A concept carries neither status nor verified, so it silently reads as stable (issue #110). Off by default because the spec reads an absent status as stable; the software-project profile raises it to \"warn\".",
266
- default: "off"
267
- })),
268
- source_resource_missing: Schema.optionalKey(LintLevel.annotate({
269
- title: "source-resource-missing",
270
- description: "A resource or sources[].resource path resolves neither in the bundle nor on disk relative to the concept (issue #106). Default \"warn\".",
271
- default: "warn"
272
- })),
273
- resource_ignored: Schema.optionalKey(LintLevel.annotate({
274
- title: "resource-ignored",
275
- description: "A resource or sources[].resource path names a file that exists locally but is gitignored, so every other checkout sees it missing (issue #279). Skipped outside a git repository and under --skip-provenance. Default \"error\".",
276
- default: "error"
277
- })),
278
- resource_untracked: Schema.optionalKey(LintLevel.annotate({
279
- title: "resource-untracked",
280
- description: "A resource or sources[].resource path names a file that exists locally but git does not track yet; not raised once the file is staged (issue #279). Skipped outside a git repository and under --skip-provenance. Default \"warn\".",
281
- default: "warn"
282
- })),
283
- resource_outside_project: Schema.optionalKey(LintLevel.annotate({
284
- title: "resource-outside-project",
285
- description: "A resource value resolves outside the project root, directly or through a symlink, so okfit never reads, stats or asks git about the target (okfit's repository check, not OKF). Default \"info\".",
286
- default: "info"
287
- })),
288
- superseded_by_orphan: Schema.optionalKey(LintLevel.annotate({
289
- title: "superseded-by-orphan",
290
- description: "A concept carries superseded_by but its status is not deprecated; superseded_by has a meaning only with status: deprecated (OKF 0.3 §5.4). Default \"warn\".",
291
- default: "warn"
292
- })),
293
- superseded_by_unresolved: Schema.optionalKey(LintLevel.annotate({
294
- title: "superseded-by-unresolved",
295
- description: "A deprecated concept's superseded_by resolves to an asset, an external value or the concept itself rather than a replacement concept (OKF 0.3 §5.4). A missing target is reported by broken-links. Default \"warn\".",
296
- default: "warn"
297
- })),
298
- generated_missing: Schema.optionalKey(LintLevel.annotate({
299
- title: "generated-missing",
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.",
301
- default: "warn"
302
- })),
303
- computation_missing: Schema.optionalKey(LintLevel.annotate({
304
- title: "computation-missing",
305
- description: "An Attested Computation has no computation: no computation key, and nothing in its Computation section that the bundle's OKF version reads as one (under 0.3 the first fenced block, §10.3; under 0.2 the text of a top-level section), so it is not attestable. Default \"warn\".",
306
- default: "warn"
307
- })),
308
- generated_at_future: Schema.optionalKey(LintLevel.annotate({
309
- title: "generated-at-future",
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".`,
311
- default: "warn"
312
- })),
313
- publication_drift: Schema.optionalKey(LintLevel.annotate({
314
- title: "publication-drift",
315
- description: `A Publication's ${OKFIT_KEY_PREFIX}renders[].body is missing or no longer matches the current body of the concept it names, so the published page may restate stale facts. Default "warn".`,
316
- default: "warn"
317
- })),
318
- publication_orphan: Schema.optionalKey(LintLevel.annotate({
319
- title: "publication-orphan",
320
- description: `A Publication's ${OKFIT_KEY_PREFIX}surface or ${OKFIT_KEY_PREFIX}renders[].path does not resolve to a concept, or ${OKFIT_KEY_PREFIX}renders is not a list of { path, body } entries. Default "error".`,
321
- default: "error"
322
- })),
323
- surface_unmatched: Schema.optionalKey(LintLevel.annotate({
324
- title: "surface-unmatched",
325
- description: "A Surface's resource glob matches no file or directory; legitimate in a brand-new monorepo, so it only warns. Default \"warn\".",
326
- default: "warn"
327
- })),
328
- index_metadata_invalid: Schema.optionalKey(LintLevel.annotate({
329
- title: "index-metadata-invalid",
330
- description: "The bundle-root index.md frontmatter carries an okf_version that is not a quoted <major>.<minor> string, or a title, description or license that is not a string; the value is read best-effort. Default \"warn\".",
331
- default: "warn"
332
- })),
333
- entry_ignored: Schema.optionalKey(LintLevel.annotate({
334
- title: "entry-ignored",
335
- description: "An entry or mapping the spec defines (a sources, verified or parameters entry, generated) lacks a REQUIRED key or has one okfit cannot read, so it is ignored (OKF 0.3 §11.2 rule 3). Default \"warn\".",
336
- default: "warn"
337
- })),
338
- value_malformed: Schema.optionalKey(LintLevel.annotate({
339
- title: "value-malformed",
340
- description: "A defined value okfit cannot read in its defined shape (wrong type, unparsable timestamp, malformed optional key) is read as absent; a malformed stale_after reads as malformed, never fresh (OKF 0.3 §5.5, §11.2). Default \"warn\".",
341
- default: "warn"
342
- })),
343
- value_unknown: Schema.optionalKey(LintLevel.annotate({
344
- title: "value-unknown",
345
- description: "A defined key carries a value outside its vocabulary (today: status); the value is kept and the concept is not read as current knowledge (OKF 0.3 §5.4, §11.2 rule 4). Default \"warn\".",
346
- default: "warn"
347
- })),
348
- non_concept_unlisted: Schema.optionalKey(LintLevel.annotate({
349
- title: "non-concept-unlisted",
350
- description: "A .md file is not a concept (no frontmatter, or no type) and matches no glob in [bundle] non_concepts. An okfit opinion, not OKF conformance (§3.2 allows such files). Silent when non_concepts is absent. Default \"warn\".",
351
- default: "warn"
352
- }))
353
- }).annotate({
354
- title: "Lint severities",
355
- description: "Per-code severity overrides. Any key omitted keeps its default."
356
- });
357
- /**
358
110
  * Scan a glob once, left to right, for a `[` or `{` that never closes; the
359
111
  * result is the rejection message tail naming the opener, or `undefined` when
360
112
  * none is left open. A backslash escapes the next character; a class closes at
@@ -385,6 +137,59 @@ const unclosedGlobMessage = (glob) => {
385
137
  if (classStart >= 0) return `"[" opens a character class that never closes; to match a literal bracket write '\\[' in single quotes or "\\\\[" in double quotes`;
386
138
  return depth > 0 ? `"{" opens a brace group that never closes; to match a literal brace write '\\{' in single quotes or "\\\\{" in double quotes` : void 0;
387
139
  };
140
+ const nameSchema = (annotations) => Schema.String.annotate(annotations).check(Schema.isPattern(Reference.NAME_PATTERN)).check(Schema.makeFilter((value) => Reference.isValidName(value) || `Expected a name that is not a reserved URL scheme, got ${JSON.stringify(value)}`));
141
+ const NAME_DESCRIPTION = "a lower-case letter, then lower-case letters, digits or hyphens, two to 32 characters in all. A URL scheme such as http, https, git or file is reserved.";
142
+ const ReferenceName = nameSchema({
143
+ title: "Name",
144
+ description: `A bundle, checkout or reference name: ${NAME_DESCRIPTION}`,
145
+ examples: ["company", "kit"]
146
+ });
147
+ /**
148
+ * What an agent may do with a bundle or checkout.
149
+ *
150
+ * @public
151
+ */
152
+ const Access = Schema.Literals(["read", "read-write"]).annotate({
153
+ title: "Access",
154
+ description: "\"read\" lets an agent read the bundle; \"read-write\" also lets it write. A checkout may narrow what the repository allows, never widen it.",
155
+ examples: ["read", "read-write"]
156
+ });
157
+ const repoField = (title, description) => Schema.String.annotate({
158
+ title,
159
+ description,
160
+ examples: ["savvy-web/okf-sandbox", "https://github.com/savvy-web/company.git"]
161
+ }).check(Schema.makeFilter((value) => Option.isSome(RepoIdentity.normalize(value)) || `Expected a repository as "owner/name" (GitHub), "host/owner/name", or an https, ssh or scp URL (an owner containing a dot needs its host, as in gitlab.com/my.group/proj), got ${JSON.stringify(value)}`));
162
+ /**
163
+ * Why `value` holds a control character, or `undefined` when it holds none: a C0 character (newline, ESC and NUL
164
+ * included), DEL, a C1 character, or the line and paragraph separators U+2028 and U+2029. A path with one is never a
165
+ * real directory name here, and the agent plugin tells paths to a model, so a config must not carry one.
166
+ */
167
+ const controlCharacterProblem = (value) => {
168
+ for (const char of value) {
169
+ const code = char.codePointAt(0);
170
+ if (code < 32 || code >= 127 && code <= 159 || code === 8232 || code === 8233) return `contains a control character (U+${code.toString(16).toUpperCase().padStart(4, "0")})`;
171
+ }
172
+ };
173
+ /** A string check refusing control characters, for a path key. */
174
+ const noControlCharacters = Schema.makeFilter((value) => {
175
+ const problem = controlCharacterProblem(value);
176
+ return problem === void 0 ? true : `Expected a path with no control characters, but ${JSON.stringify(value)} ${problem}`;
177
+ });
178
+ /** Why `value` cannot be where git fetches a checkout from, or `undefined`: everything else git accepts is allowed. */
179
+ const fetchUrlProblem = (value) => {
180
+ if (value.trim() === "") return "is empty";
181
+ if (value.startsWith("-")) return "starts with \"-\", which git would read as an option";
182
+ if (/^(ext|fd)::/i.test(value.trim())) return "uses a transport that runs a command (ext:: or fd::)";
183
+ };
184
+ /** Why `value` is not a directory inside a repository, or `undefined` when it is one. */
185
+ const repositoryPathProblem = (value) => {
186
+ if (value.trim() === "") return "is empty";
187
+ const control = controlCharacterProblem(value);
188
+ if (control !== void 0) return control;
189
+ if (value.includes("\\")) return "contains a backslash";
190
+ if (value.startsWith("/") || /^[A-Za-z]:/.test(value)) return "is absolute";
191
+ if (value.split("/").some((segment) => segment === ".." || segment === ".")) return "has a \".\" or \"..\" segment";
192
+ };
388
193
  /**
389
194
  * The `OkfitConfig` struct schema. Exported only so the `OkfitConfigFields`
390
195
  * type below is reachable from the rollup; the barrel never re-exports this
@@ -397,13 +202,19 @@ const okfitConfigFields = Schema.Struct({
397
202
  description: "The okf_version okfit writes into a bundle-root index.md that declares none (okfit init, okfit sync). The bundle's own declaration decides how it is read. When the root index.md declares a different version, the lint config-okf-version-stale reports this value as stale.",
398
203
  examples: ["0.3"]
399
204
  })),
205
+ repo: Schema.optionalKey(repoField("This repository", "The consumer's own repository as \"owner/name\" (GitHub) or a git URL. Falls back to the origin remote of the project root. Lets a reference to this repository resolve to the project root.")),
400
206
  bundle: Schema.optionalKey(Schema.Struct({
207
+ name: Schema.optionalKey(nameSchema({
208
+ title: "Bundle name",
209
+ description: `The bundle's name, defaulting to the base name of the bundle directory: ${NAME_DESCRIPTION}`,
210
+ examples: ["patterns"]
211
+ })),
401
212
  path: Schema.optionalKey(Schema.String.annotate({
402
213
  title: "Bundle directory",
403
214
  description: "The OKF bundle's root directory, relative to the project root.",
404
215
  default: "okf",
405
216
  examples: ["okf"]
406
- })),
217
+ }).check(noControlCharacters)),
407
218
  profile: Schema.optionalKey(Schema.String.annotate({
408
219
  title: "Profile name",
409
220
  description: "The named profile merged under `DEFAULTS < profile < file`, or \"none\" to disable profile merging.",
@@ -467,6 +278,132 @@ const okfitConfigFields = Schema.Struct({
467
278
  title: "Tag declarations",
468
279
  description: "One entry per tag, keyed by tag name."
469
280
  })),
281
+ bundle_set: Schema.optionalKey(Schema.Struct({ discover: Schema.Array(Schema.String).annotate({
282
+ title: "Discovery globs",
283
+ description: "Globs, relative to the project root (the directory of this config file, or for a config at .config/okfit.toml the directory that holds .config, not .config itself), that name the okfit.toml of each bundle the repository holds.",
284
+ examples: [["*/okfit.toml"]]
285
+ }) }).annotate({
286
+ title: "Bundle set",
287
+ description: "How a knowledge repository finds the bundles it holds."
288
+ })),
289
+ bundles: Schema.optionalKey(Schema.Record(Schema.String, Schema.Struct({
290
+ path: Schema.String.annotate({
291
+ title: "Bundle path",
292
+ description: "The bundle's root directory, relative to this config file's directory.",
293
+ examples: ["../shared/okf"]
294
+ }).check(noControlCharacters),
295
+ access: Schema.optionalKey(Access)
296
+ }).annotate({
297
+ title: "Bundle",
298
+ description: "A bundle declared directly, with no checkout."
299
+ })).check(Schema.isPropertyNames(ReferenceName)).annotate({
300
+ title: "Bundles",
301
+ description: "Bundles declared directly, keyed by bundle name. Each carries its own okfit.toml."
302
+ })),
303
+ checkouts: Schema.optionalKey(Schema.Record(Schema.String, Schema.Struct({
304
+ repo: repoField("Checkout repository", "The repository this checkout holds."),
305
+ path: Schema.String.annotate({
306
+ title: "Checkout path",
307
+ description: "Where the checkout sits, relative to this config file's directory.",
308
+ examples: [".repos/company"]
309
+ }).check(noControlCharacters),
310
+ kind: Schema.optionalKey(Schema.Literals([
311
+ "submodule",
312
+ "clone",
313
+ "path"
314
+ ]).annotate({
315
+ title: "Checkout kind",
316
+ description: "How the checkout is present: a git submodule, a separate clone, or a plain path.",
317
+ examples: ["submodule"]
318
+ })),
319
+ branch: Schema.optionalKey(Schema.String.annotate({
320
+ title: "Checkout branch",
321
+ description: "The remote branch a managed checkout follows. Absent: the remote's default branch. A git branch name, as `git check-ref-format --branch` accepts it: no ASCII space or control characters, no \"..\", no leading \"-\", none of ~ ^ : ? * [ \\, no leading or trailing \"/\", no trailing \".\" or \".lock\", no \"@{\"; \"HEAD\" is refused.",
322
+ examples: ["main", "release/1.x"]
323
+ }).check(GitRef.branchNameCheck)),
324
+ url: Schema.optionalKey(Schema.String.annotate({
325
+ title: "Checkout URL",
326
+ description: "Where to fetch the repository from, when that is not the https URL derived from `repo`: an ssh or scp address, a mirror, GitHub Enterprise, a local path or a file:// URL. `repo` stays the identity references resolve against. May not be empty, hold a control character, start with `-` or use the ext:: or fd:: transports. Not allowed on a submodule from the local config file.",
327
+ examples: ["git@github.com:owner/name.git"]
328
+ }).check(noControlCharacters).check(Schema.makeFilter((value) => {
329
+ const problem = fetchUrlProblem(value);
330
+ return problem === void 0 ? true : `Expected a fetch URL, but ${JSON.stringify(value)} ${problem}`;
331
+ }))),
332
+ bundles: Schema.optionalKey(Schema.Array(ReferenceName).annotate({
333
+ title: "Selected bundles",
334
+ description: "Which of the repository's bundles to take. Absent: every bundle its root config discovers.",
335
+ examples: [["patterns", "kit"]]
336
+ })),
337
+ access: Schema.optionalKey(Access),
338
+ purpose: Schema.optionalKey(Schema.String.annotate({
339
+ title: "Purpose",
340
+ description: "What this checkout is for, told to an agent at session start."
341
+ })),
342
+ layout: Schema.optionalKey(Schema.String.annotate({
343
+ title: "Layout",
344
+ description: "How the checkout is organised, told to an agent at session start."
345
+ })),
346
+ start_here: Schema.optionalKey(Schema.String.annotate({
347
+ title: "Start here",
348
+ description: "The first path an agent should read in this checkout."
349
+ }))
350
+ }).annotate({
351
+ title: "Checkout",
352
+ description: "A repository checkout that is present here."
353
+ })).check(Schema.isPropertyNames(ReferenceName)).annotate({
354
+ title: "Checkouts",
355
+ description: "Repository checkouts present here, keyed by name. A checkout states where a repository is."
356
+ })),
357
+ references: Schema.optionalKey(Schema.Record(Schema.String, Schema.Struct({
358
+ repo: repoField("Reference repository", "The repository the name stands for."),
359
+ path: Schema.optionalKey(Schema.String.annotate({
360
+ title: "Reference path",
361
+ description: "A relative directory inside that repository the name is rooted at: no leading \"/\", drive letter, backslash, \".\" or \"..\" segment.",
362
+ examples: ["kit"]
363
+ }).check(Schema.makeFilter((value) => {
364
+ const problem = repositoryPathProblem(value);
365
+ return problem === void 0 ? true : `Expected a relative directory inside the repository, but ${JSON.stringify(value)} ${problem}`;
366
+ })))
367
+ }).annotate({
368
+ title: "Reference",
369
+ description: "What a name: prefix means in this bundle."
370
+ })).check(Schema.isPropertyNames(ReferenceName)).annotate({
371
+ title: "Named references",
372
+ description: "Names a link or resource may use as name:path, keyed by name."
373
+ })),
374
+ contribute: Schema.optionalKey(Schema.Struct({
375
+ flow: Schema.optionalKey(Schema.Literals(["pull-request", "push"]).annotate({
376
+ title: "Contribution flow",
377
+ description: "How a change reaches this repository.",
378
+ examples: ["pull-request"]
379
+ })),
380
+ branch: Schema.optionalKey(Schema.String.annotate({
381
+ title: "Branch pattern",
382
+ description: "The branch a change is made on; {topic} stands for the change's topic.",
383
+ examples: ["okf/{topic}"]
384
+ })),
385
+ merge: Schema.optionalKey(Schema.Literals([
386
+ "auto-squash",
387
+ "squash",
388
+ "none"
389
+ ]).annotate({
390
+ title: "Merge policy",
391
+ description: "How an accepted change is merged.",
392
+ examples: ["auto-squash"]
393
+ })),
394
+ signed: Schema.optionalKey(Schema.Boolean.annotate({
395
+ title: "Signed commits",
396
+ description: "Whether commits must be signed."
397
+ })),
398
+ needs_approval: Schema.optionalKey(Schema.Array(Schema.String).annotate({
399
+ title: "Approval globs",
400
+ description: "Globs of paths whose change needs human approval.",
401
+ examples: [[".github/**", "**/okfit.toml"]]
402
+ }))
403
+ }).annotate({
404
+ title: "Contribution policy",
405
+ description: "How to contribute to this knowledge repository."
406
+ })),
470
407
  extensions: Schema.Record(Schema.String, Schema.Unknown)
471
408
  });
472
409
  /**
@@ -520,7 +457,13 @@ const SCHEMA_DIRECTIVE = `#:schema ${okfitConfigSchemaHost.$id}\n\n`;
520
457
  */
521
458
  const okfitConfigDocumentFields = Schema.StructWithRest(Schema.Struct({
522
459
  okf_version: okfitConfigFields.fields.okf_version,
460
+ repo: okfitConfigFields.fields.repo,
523
461
  bundle: okfitConfigFields.fields.bundle,
462
+ bundle_set: okfitConfigFields.fields.bundle_set,
463
+ bundles: okfitConfigFields.fields.bundles,
464
+ checkouts: okfitConfigFields.fields.checkouts,
465
+ references: okfitConfigFields.fields.references,
466
+ contribute: okfitConfigFields.fields.contribute,
524
467
  concepts: okfitConfigFields.fields.concepts,
525
468
  lifecycle: okfitConfigFields.fields.lifecycle,
526
469
  actors: okfitConfigFields.fields.actors,
@@ -598,7 +541,14 @@ const LINT_KEY = {
598
541
  "frontmatter-missing": "frontmatter_missing",
599
542
  "type-missing": "type_missing",
600
543
  "symlink-escape": "symlink_escape",
601
- "non-concept-unlisted": "non_concept_unlisted"
544
+ "non-concept-unlisted": "non_concept_unlisted",
545
+ "reference-not-mounted": "reference_not_mounted",
546
+ "reference-missing": "reference_missing",
547
+ "reference-undeclared": "reference_undeclared",
548
+ "reference-local-only": "reference_local_only",
549
+ "config-misplaced-key": "config_misplaced_key",
550
+ "config-local-tracked": "config_local_tracked",
551
+ "bundle-config-invalid": "bundle_config_invalid"
602
552
  };
603
553
  const DEFAULT_LINT = {
604
554
  broken_links: "warn",
@@ -644,7 +594,14 @@ const DEFAULT_LINT = {
644
594
  frontmatter_missing: "warn",
645
595
  type_missing: "warn",
646
596
  symlink_escape: "warn",
647
- non_concept_unlisted: "warn"
597
+ non_concept_unlisted: "warn",
598
+ reference_not_mounted: "info",
599
+ reference_missing: "warn",
600
+ reference_undeclared: "warn",
601
+ reference_local_only: "info",
602
+ config_misplaced_key: "warn",
603
+ config_local_tracked: "warn",
604
+ bundle_config_invalid: "error"
648
605
  };
649
606
  const toSeverity = (level) => level === "warn" ? "warning" : level;
650
607
  const severityFor = (config, code) => {
@@ -719,4 +676,4 @@ const OkfitConfig = Object.assign(OkfitConfigWire, {
719
676
  */
720
677
  var OkfitConfigFile = class extends ConfigFile.Service()("@okfit/core/OkfitConfigFile") {};
721
678
 
722
- export { CONFIG_SCHEMA_VERSION, FieldDeclaration, LintLevel, LintTable, OkfitConfig, OkfitConfigFile, SCHEMA_DIRECTIVE, StaleAfterDuration, TagDeclaration, TypeDeclaration, okfitConfigDocumentFields, okfitConfigFields, okfitConfigSchemaHost };
679
+ export { Access, CONFIG_SCHEMA_VERSION, FieldDeclaration, LintLevel, LintTable, OkfitConfig, OkfitConfigFile, SCHEMA_DIRECTIVE, StaleAfterDuration, TagDeclaration, TypeDeclaration, okfitConfigDocumentFields, okfitConfigFields, okfitConfigSchemaHost };
package/Reference.js ADDED
@@ -0,0 +1,65 @@
1
+ import { Option } from "effect";
2
+
3
+ // src/Reference.ts
4
+ /**
5
+ * Named-reference parsing: `name:path` where `name` is a declared reference root.
6
+ * URL schemes are reserved so a link such as `https://x.dev` is never read as a reference. @public
7
+ */
8
+ var Reference = class Reference {
9
+ constructor() {}
10
+ /** URL schemes a reference name may not take. */
11
+ static RESERVED_SCHEMES = /* @__PURE__ */ new Set([
12
+ "http",
13
+ "https",
14
+ "ftp",
15
+ "file",
16
+ "mailto",
17
+ "git",
18
+ "ssh",
19
+ "data",
20
+ "urn",
21
+ "tel",
22
+ "ws",
23
+ "wss",
24
+ "about",
25
+ "javascript",
26
+ "magnet",
27
+ "sms",
28
+ "geo",
29
+ "npm",
30
+ "doi",
31
+ "blob",
32
+ "chrome",
33
+ "vscode",
34
+ "slack",
35
+ "irc",
36
+ "xmpp",
37
+ "sip",
38
+ "news",
39
+ "ldap",
40
+ "s3",
41
+ "gs",
42
+ "jar",
43
+ "view-source"
44
+ ]);
45
+ /**
46
+ * The shape of a valid name, as a Unicode-mode RegExp so a JSON Schema `pattern` can be derived from it.
47
+ * The reserved schemes are excluded separately, by {@link Reference.isValidName}.
48
+ */
49
+ static NAME_PATTERN = /^[a-z][a-z0-9-]{1,31}$/u;
50
+ /** Lower-case letter first, then letters, digits or hyphens, two to 32 characters, not reserved; two characters minimum so a drive letter is never a name. */
51
+ static isValidName = (name) => Reference.NAME_PATTERN.test(name) && !Reference.RESERVED_SCHEMES.has(name);
52
+ /** `Some` only when the text before the first `:` is a declared name and the rest does not start with `//`. */
53
+ static parse = (value, names) => {
54
+ const colon = value.indexOf(":");
55
+ if (colon < 0) return Option.none();
56
+ const name = value.slice(0, colon);
57
+ const path = value.slice(colon + 1);
58
+ return names.has(name) && !path.startsWith("//") ? Option.some({
59
+ name,
60
+ path
61
+ }) : Option.none();
62
+ };
63
+ };
64
+
65
+ export { Reference };
@@ -0,0 +1,46 @@
1
+ import { GitRemote } from "@effected/git";
2
+ import { Option } from "effect";
3
+
4
+ // src/RepoIdentity.ts
5
+ const WHITESPACE = /\s/;
6
+ const collapseTrailingSlashes = (value) => {
7
+ let end = value.length;
8
+ while (end > 1 && value.charCodeAt(end - 1) === 47 && value.charCodeAt(end - 2) === 47) end--;
9
+ return end === value.length ? value : value.slice(0, end);
10
+ };
11
+ /**
12
+ * Canonical repository identity: `host/owner/name`, lower-case, with no `.git` suffix and no trailing slash.
13
+ * Accepts `owner/name` shorthand (GitHub), URL remotes (user, port and `[::1]` hosts allowed), and scp-like
14
+ * `git@host:owner/name` remotes. Pure string work with no `node:` imports. @public
15
+ *
16
+ * @remarks
17
+ * The address is read by `GitRemote.parseIdentity` from `@effected/git` (URL, scp or path form, as git reads it, so
18
+ * an IPv6 literal and the scp-versus-path ambiguity are decided there) with `defaultHost: "github.com"`,
19
+ * `foldCase: "always"`, `minSegments: 2` and `strict: true`: a scheme-less path is exactly `owner/name` shorthand or
20
+ * `host/owner/name`, and the path needs at least two segments after the host. okfit's own rule is the pre-check: a value
21
+ * carrying whitespace, `?` or `#` does not normalise, and a run of trailing slashes is collapsed to one before the kit
22
+ * reads it (`strict` takes one on a URL, scp or scheme-less `host/owner/name/` address, and the shorthand `owner/name/` has no identity). Under `strict` an empty, bare `.git` or doubled-`.git` name has no
23
+ * identity either. An owner containing a dot is not shorthand (`my.group/proj`), because the kit reads a first segment
24
+ * holding a dot as a host; it needs its host spelled out, as in `gitlab.com/my.group/proj`.
25
+ */
26
+ var RepoIdentity = class RepoIdentity {
27
+ constructor() {}
28
+ /** The canonical identity of a repository reference, or `None` when it does not normalise. */
29
+ static normalize = (value) => {
30
+ if (value === "" || WHITESPACE.test(value) || value.includes("?") || value.includes("#")) return Option.none();
31
+ return Option.map(GitRemote.parseIdentity(collapseTrailingSlashes(value), {
32
+ defaultHost: "github.com",
33
+ foldCase: "always",
34
+ minSegments: 2,
35
+ strict: true
36
+ }), String);
37
+ };
38
+ /** True when both values normalize and the identities match. */
39
+ static equals = (a, b) => {
40
+ const left = RepoIdentity.normalize(a);
41
+ const right = RepoIdentity.normalize(b);
42
+ return Option.isSome(left) && Option.isSome(right) && left.value === right.value;
43
+ };
44
+ };
45
+
46
+ export { RepoIdentity };