@okfit/engine 0.14.0 → 0.15.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/verify/run.js CHANGED
@@ -1,10 +1,13 @@
1
- import { VerifyConceptNotFoundError, VerifyUnsupportedFrontmatterError } from "../errors.js";
1
+ import { VerifyConceptNotFoundError, VerifyNothingToRevokeError, VerifyUnsupportedFrontmatterError } from "../errors.js";
2
2
  import { documentNewline, locate, locateTopLevelScalar, locateVerifiedAt, stripBom } from "./locate.js";
3
+ import { locateIntegrity, removeIntegrityVerified, spliceIntegrityVerified } from "./integrity.js";
3
4
  import { orderVerifyEdits, quoteLike, splice, spliceTopLevelScalar } from "./splice.js";
5
+ import { changeSince } from "./diff.js";
6
+ import { locateVerifiedEntries } from "./revoke.js";
4
7
  import { resolveBatchTypes, selectAttestable, selectPickerCandidates, selectStaleCandidates } from "./select.js";
5
8
  import { Bundle, ConceptId, Derive, Timestamp } from "@okfit/core";
6
9
  import { DateTime, Effect, FileSystem, Option, Path, Schema } from "effect";
7
- import { Derivation } from "@okfit/profiles";
10
+ import { Derivation, Trust } from "@okfit/profiles";
8
11
  import { MarkdownEdit } from "@effected/markdown";
9
12
 
10
13
  //#region src/verify/run.ts
@@ -26,6 +29,7 @@ const UNDECODABLE_CODES = /* @__PURE__ */ new Set([
26
29
  ]);
27
30
  /** Steps 9-14 of runVerify: read, locate (fail closed), splice; no write. */
28
31
  const prepareVerify = Effect.fn("okfit/verify/prepareVerify")(function* (bundle, concept, actor, at, status, staleAfter = void 0) {
32
+ const content = yield* Derivation.contentDigest(concept.frontmatter.raw, concept.document.source);
29
33
  const fs = yield* FileSystem.FileSystem;
30
34
  const absolutePath = (yield* Path.Path).join(bundle.root, concept.path);
31
35
  const source = new TextDecoder("utf-8", { ignoreBOM: true }).decode(yield* fs.readFile(absolutePath));
@@ -74,14 +78,26 @@ const prepareVerify = Effect.fn("okfit/verify/prepareVerify")(function* (bundle,
74
78
  });
75
79
  staleEdit = spliceTopLevelScalar(target, "stale_after", staleAfter, newline);
76
80
  }
77
- const ordered = orderVerifyEdits(verifiedEdit, statusEdit);
81
+ const integrity = yield* locateIntegrity(text);
82
+ if (integrity._tag === "unsupported") return yield* new VerifyUnsupportedFrontmatterError({
83
+ id: concept.id,
84
+ shape: integrity.shape,
85
+ key: "integrity"
86
+ });
87
+ const integrityEdit = spliceIntegrityVerified(integrity, text, {
88
+ by: actor,
89
+ at,
90
+ content
91
+ }, newline);
92
+ const ordered = orderVerifyEdits(verifiedEdit, statusEdit, integrityEdit);
78
93
  const edits = staleEdit === void 0 ? ordered : [...ordered, staleEdit].toSorted((a, b) => a.offset - b.offset);
79
94
  return {
80
95
  absolutePath,
81
96
  finalText: bom + MarkdownEdit.applyAll(text, edits),
82
97
  fragment: staleEdit === void 0 || staleAfter === void 0 ? verifiedPreview : `${verifiedPreview.replace(/(?:\r\n|\n)$/, "")}${newline}stale_after: ${staleAfter}`,
83
98
  statusFragment: statusEdit?.content ?? null,
84
- priorAt
99
+ priorAt,
100
+ content
85
101
  };
86
102
  });
87
103
  /** The I4/V-16 atomic write: real path, temp beside it, mode preserved, rename. */
@@ -140,13 +156,13 @@ const resolveConcept = (bundle, rawId) => Effect.gen(function* () {
140
156
  const runVerify = Effect.fn("okfit/verify/runVerify")(function* (options) {
141
157
  const bundle = yield* Bundle.load({ root: options.bundleRoot });
142
158
  const { id, concept } = yield* resolveConcept(bundle, options.id);
143
- const actor = yield* Derivation.generatedBy({
144
- writer: "human",
159
+ const actor = yield* Derivation.verifier({
145
160
  cwd: options.projectRoot,
146
161
  config: options.config
147
162
  });
148
163
  const at = Schema.encodeSync(Timestamp)(options.at);
149
164
  const prepared = yield* prepareVerify(bundle, concept, actor, at, options.status);
165
+ const prior = yield* Trust.signal(concept, options.config, options.at);
150
166
  if (!options.dryRun) yield* writeVerified(prepared.absolutePath, prepared.finalText);
151
167
  return {
152
168
  id,
@@ -161,14 +177,99 @@ const runVerify = Effect.fn("okfit/verify/runVerify")(function* (options) {
161
177
  from: concept.frontmatter.status ?? null,
162
178
  to: options.status
163
179
  },
164
- statusFragment: prepared.statusFragment
180
+ statusFragment: prepared.statusFragment,
181
+ content: prepared.content,
182
+ priorDrift: prior.drift?.reason ?? null
183
+ };
184
+ });
185
+ /**
186
+ * Read-only: is the concept's prior human verification drifted, and if so from
187
+ * when was it bound? The CLI asks this before `runVerify` so it can show what
188
+ * changed. Writes nothing.
189
+ *
190
+ * @internal
191
+ */
192
+ const inspectDrift = Effect.fn("okfit/verify/inspectDrift")(function* (options) {
193
+ const bundle = yield* Bundle.load({ root: options.bundleRoot });
194
+ const { id, concept } = yield* resolveConcept(bundle, options.id);
195
+ const path = yield* Path.Path;
196
+ const signal = yield* Trust.signal(concept, options.config, options.now);
197
+ const boundAt = concept.frontmatter.integrity?.verified?.at;
198
+ return {
199
+ id,
200
+ absolutePath: path.join(bundle.root, concept.path),
201
+ drift: signal.drift?.reason ?? null,
202
+ ...boundAt === void 0 ? {} : { boundAt }
203
+ };
204
+ });
205
+ /**
206
+ * `okfit verify --revoke`: removes every `verified` entry by the resolved
207
+ * human actor (the same git identity `verify` records) and, when
208
+ * `integrity.verified` is bound to that actor, that slot too, deleting the
209
+ * whole `integrity` block only when nothing else is left in it. Every cut is a
210
+ * byte-precise splice; an unsupported `verified` or `integrity` shape fails
211
+ * closed with the file untouched, and an actor with no entry fails
212
+ * `VerifyNothingToRevokeError`. Another actor's entries and binding are never
213
+ * touched, so they then read as `entry-superseded` or unbound by themselves.
214
+ *
215
+ * @internal
216
+ */
217
+ const runRevoke = Effect.fn("okfit/verify/runRevoke")(function* (options) {
218
+ const bundle = yield* Bundle.load({ root: options.bundleRoot });
219
+ const { id, concept } = yield* resolveConcept(bundle, options.id);
220
+ const actor = yield* Derivation.verifier({
221
+ cwd: options.projectRoot,
222
+ config: options.config
223
+ });
224
+ const fs = yield* FileSystem.FileSystem;
225
+ const absolutePath = (yield* Path.Path).join(bundle.root, concept.path);
226
+ const source = new TextDecoder("utf-8", { ignoreBOM: true }).decode(yield* fs.readFile(absolutePath));
227
+ const { text, bom } = stripBom(source);
228
+ const entries = yield* locateVerifiedEntries(text, actor);
229
+ if (entries._tag === "unsupported") return yield* new VerifyUnsupportedFrontmatterError({
230
+ id,
231
+ shape: entries.shape,
232
+ key: "verified"
233
+ });
234
+ if (entries._tag === "none") return yield* new VerifyNothingToRevokeError({
235
+ id,
236
+ actor
237
+ });
238
+ const integrity = yield* locateIntegrity(text);
239
+ if (integrity._tag === "unsupported") return yield* new VerifyUnsupportedFrontmatterError({
240
+ id,
241
+ shape: integrity.shape,
242
+ key: "integrity"
243
+ });
244
+ const unbind = integrity._tag === "replace" && integrity.boundBy === actor ? removeIntegrityVerified(integrity, text) : { _tag: "none" };
245
+ if (unbind._tag === "unsupported") return yield* new VerifyUnsupportedFrontmatterError({
246
+ id,
247
+ shape: unbind.shape,
248
+ key: "integrity"
249
+ });
250
+ const edits = [...entries.removals.map((span) => MarkdownEdit.make({
251
+ offset: span.start,
252
+ length: span.end - span.start,
253
+ content: ""
254
+ })), ...unbind._tag === "edit" ? [unbind.edit] : []].toSorted((a, b) => a.offset - b.offset);
255
+ const finalText = bom + MarkdownEdit.applyAll(text, edits);
256
+ const removed = (concept.frontmatter.verified ?? []).filter((entry) => entry.by === actor).map((entry) => Schema.encodeSync(Timestamp)(entry.at));
257
+ if (!options.dryRun) yield* writeVerified(absolutePath, finalText);
258
+ return {
259
+ id,
260
+ bundleRoot: bundle.root,
261
+ conceptPath: concept.path,
262
+ by: actor,
263
+ removed,
264
+ bindingCleared: unbind._tag === "edit",
265
+ dryRun: options.dryRun
165
266
  };
166
267
  });
167
268
  /**
168
269
  * Issue #138. Attests every concept selected by `options.types` (or, when
169
270
  * empty, every type whose declaration sets `require_verified = true`) that
170
- * is not a draft, is not deprecated (#143) and does not already carry a `verified` entry by the
171
- * resolved actor. Every candidate is located FIRST -- an unsupported
271
+ * is not a draft, is not deprecated (#143) and whose `verified` entry by the
272
+ * resolved actor does not already bind its current content (`Trust.signals`). Every candidate is located FIRST -- an unsupported
172
273
  * `verified` shape on any one of them fails the whole batch with nothing
173
274
  * written, mirroring `runVerify`'s own fail-closed rule at batch scale.
174
275
  *
@@ -177,13 +278,13 @@ const runVerify = Effect.fn("okfit/verify/runVerify")(function* (options) {
177
278
  const runVerifyBatch = Effect.fn("okfit/verify/runVerifyBatch")(function* (options) {
178
279
  const bundle = yield* Bundle.load({ root: options.bundleRoot });
179
280
  const types = yield* resolveBatchTypes(options.config, options.types);
180
- const actor = yield* Derivation.generatedBy({
181
- writer: "human",
281
+ const actor = yield* Derivation.verifier({
182
282
  cwd: options.projectRoot,
183
283
  config: options.config
184
284
  });
185
285
  const at = Schema.encodeSync(Timestamp)(options.at);
186
- const selection = selectAttestable(bundle, types, actor);
286
+ const signals = yield* Trust.signals(bundle, options.config, options.at);
287
+ const selection = selectAttestable(bundle, types, actor, signals);
187
288
  const prepared = [];
188
289
  for (const concept of selection.candidates) prepared.push({
189
290
  id: concept.id,
@@ -218,8 +319,7 @@ const runVerifyBatch = Effect.fn("okfit/verify/runVerifyBatch")(function* (optio
218
319
  */
219
320
  const runVerifyIds = Effect.fn("okfit/verify/runVerifyIds")(function* (options) {
220
321
  const bundle = yield* Bundle.load({ root: options.bundleRoot });
221
- const actor = yield* Derivation.generatedBy({
222
- writer: "human",
322
+ const actor = yield* Derivation.verifier({
223
323
  cwd: options.projectRoot,
224
324
  config: options.config
225
325
  });
@@ -253,6 +353,11 @@ const runVerifyIds = Effect.fn("okfit/verify/runVerifyIds")(function* (options)
253
353
  skipped: []
254
354
  };
255
355
  });
356
+ /** The rows with `path` joined onto the bundle root, so the picker's callers get absolute file paths. */
357
+ const absolutePaths = (rows, path, root) => rows.map((row) => ({
358
+ ...row,
359
+ path: path.join(root, row.path)
360
+ }));
256
361
  /**
257
362
  * The interactive verify picker's starting point: loads the bundle, resolves
258
363
  * the human actor from git exactly as {@link runVerify} does, and selects the
@@ -262,14 +367,15 @@ const runVerifyIds = Effect.fn("okfit/verify/runVerifyIds")(function* (options)
262
367
  */
263
368
  const loadPickerCandidates = Effect.fn("okfit/verify/loadPickerCandidates")(function* (options) {
264
369
  const bundle = yield* Bundle.load({ root: options.bundleRoot });
265
- const by = yield* Derivation.generatedBy({
266
- writer: "human",
370
+ const by = yield* Derivation.verifier({
267
371
  cwd: options.projectRoot,
268
372
  config: options.config
269
373
  });
374
+ const signals = yield* Trust.signals(bundle, options.config, yield* DateTime.now);
375
+ const path = yield* Path.Path;
270
376
  return {
271
377
  by,
272
- candidates: selectPickerCandidates(bundle, options.config, by)
378
+ candidates: absolutePaths(selectPickerCandidates(bundle, options.config, by, signals), path, bundle.root)
273
379
  };
274
380
  });
275
381
  /**
@@ -281,16 +387,46 @@ const loadPickerCandidates = Effect.fn("okfit/verify/loadPickerCandidates")(func
281
387
  */
282
388
  const loadStaleCandidates = Effect.fn("okfit/verify/loadStaleCandidates")(function* (options) {
283
389
  const bundle = yield* Bundle.load({ root: options.bundleRoot });
284
- const by = yield* Derivation.generatedBy({
285
- writer: "human",
390
+ const by = yield* Derivation.verifier({
286
391
  cwd: options.projectRoot,
287
392
  config: options.config
288
393
  });
394
+ const signals = yield* Trust.signals(bundle, options.config, options.now);
395
+ const path = yield* Path.Path;
289
396
  return {
290
397
  by,
291
- candidates: selectStaleCandidates(bundle, Derive.staleReport(bundle, options.now), by)
398
+ candidates: absolutePaths(selectStaleCandidates(bundle, Derive.staleReport(bundle, options.now), by, signals), path, bundle.root)
292
399
  };
293
400
  });
401
+ /**
402
+ * The verify picker's diff previews: for each drifted candidate, in candidate
403
+ * order and one at a time, what changed in its file since its verification was
404
+ * bound ({@link changeSince}). A candidate with no binding is `no-baseline`
405
+ * `unbound` without touching git, and a git failure reading the history is
406
+ * `no-baseline` `not-a-repository`, so a preview never fails the picker. Rows
407
+ * that are not drifted get no entry. Reads only.
408
+ *
409
+ * @public
410
+ */
411
+ const loadPreviews = Effect.fn("okfit/verify/loadPreviews")(function* (candidates) {
412
+ const previews = /* @__PURE__ */ new Map();
413
+ for (const candidate of candidates) {
414
+ if (candidate.integrity !== "drifted") continue;
415
+ const at = candidate.boundAt === null ? void 0 : DateTime.make(candidate.boundAt);
416
+ const preview = at === void 0 || Option.isNone(at) ? {
417
+ _tag: "no-baseline",
418
+ reason: "unbound"
419
+ } : yield* changeSince({
420
+ file: candidate.path,
421
+ at: DateTime.toUtc(at.value)
422
+ }).pipe(Effect.catchTag("GitCommandError", () => Effect.succeed({
423
+ _tag: "no-baseline",
424
+ reason: "not-a-repository"
425
+ })));
426
+ previews.set(candidate.id, preview);
427
+ }
428
+ return previews;
429
+ });
294
430
 
295
431
  //#endregion
296
- export { loadPickerCandidates, loadStaleCandidates, runVerify, runVerifyBatch, runVerifyIds };
432
+ export { inspectDrift, loadPickerCandidates, loadPreviews, loadStaleCandidates, runRevoke, runVerify, runVerifyBatch, runVerifyIds };
package/verify/select.js CHANGED
@@ -1,15 +1,22 @@
1
1
  import { VerifySelectionError } from "../errors.js";
2
- import { Effect } from "effect";
2
+ import { DateTime, Effect } from "effect";
3
3
 
4
4
  //#region src/verify/select.ts
5
5
  /**
6
+ * Whether `concept` is verified by `actor` AND that verification still binds
7
+ * its content: the signal is `current` and `integrity.verified` names `actor`.
8
+ * A drifted concept, or one whose current binding is another actor's, is not.
9
+ */
10
+ const attestedBy = (concept, actor, signals) => signals.get(concept.id)?.integrity === "current" && concept.frontmatter.integrity?.verified?.by === actor;
11
+ /**
6
12
  * Issue #138/#143: which concepts of `types` the actor may attest in one
7
13
  * batch. A draft is unsettled and a deprecated concept is retired (#143), so
8
- * both are skipped before the already-verified check.
14
+ * both are skipped before the already-verified check. A concept whose
15
+ * verification has drifted, or is bound to another actor, is a candidate.
9
16
  *
10
17
  * @public
11
18
  */
12
- const selectAttestable = (bundle, types, actor) => {
19
+ const selectAttestable = (bundle, types, actor, signals) => {
13
20
  const candidates = [];
14
21
  const skipped = [];
15
22
  for (const [id, concept] of bundle.concepts) {
@@ -22,7 +29,7 @@ const selectAttestable = (bundle, types, actor) => {
22
29
  });
23
30
  continue;
24
31
  }
25
- if ((concept.frontmatter.verified ?? []).some((entry) => entry.by === actor)) {
32
+ if (attestedBy(concept, actor, signals)) {
26
33
  skipped.push({
27
34
  id,
28
35
  reason: "already-verified"
@@ -37,28 +44,36 @@ const selectAttestable = (bundle, types, actor) => {
37
44
  };
38
45
  };
39
46
  const requireVerifiedTypes = (config) => new Set(Object.entries(config.types ?? {}).flatMap(([name, spec]) => spec.require_verified === true ? [name] : []));
47
+ const boundAtOf = (concept) => {
48
+ const at = concept.frontmatter.integrity?.verified?.at;
49
+ return at === void 0 ? null : DateTime.formatIso(at);
50
+ };
40
51
  /**
41
52
  * Every concept whose type sets `require_verified` that `actor` has not
42
- * attested: drafts included, deprecated concepts and the actor's own
43
- * attestations excluded. Sorted by type, then id; grouping is the caller's.
53
+ * attested: drafts included, deprecated concepts and the actor's own still-bound
54
+ * attestations excluded (a drifted one is offered again). Sorted by type, then id; grouping is the caller's.
44
55
  *
45
56
  * @public
46
57
  */
47
- const selectPickerCandidates = (bundle, config, actor) => {
58
+ const selectPickerCandidates = (bundle, config, actor, signals) => {
48
59
  const types = requireVerifiedTypes(config);
49
60
  const rows = [];
50
61
  for (const [id, concept] of bundle.concepts) {
51
62
  const { type, status, title, description } = concept.frontmatter;
52
63
  if (!types.has(type) || status === "deprecated") continue;
53
64
  const verified = concept.frontmatter.verified ?? [];
54
- if (verified.some((entry) => entry.by === actor)) continue;
65
+ if (attestedBy(concept, actor, signals)) continue;
55
66
  rows.push({
56
67
  id,
57
68
  type,
58
69
  status: status === "draft" ? "draft" : "stable",
59
70
  title: title ?? null,
60
71
  description: description ?? null,
61
- otherAttestations: verified.length
72
+ otherAttestations: verified.filter((entry) => entry.by !== actor).length,
73
+ integrity: signals.get(id)?.integrity ?? "none",
74
+ stale: signals.get(id)?.stale ?? false,
75
+ path: concept.path,
76
+ boundAt: boundAtOf(concept)
62
77
  });
63
78
  }
64
79
  return rows.toSorted((a, b) => a.type < b.type ? -1 : a.type > b.type ? 1 : a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
@@ -72,7 +87,7 @@ const selectPickerCandidates = (bundle, config, actor) => {
72
87
  *
73
88
  * @public
74
89
  */
75
- const selectStaleCandidates = (bundle, items, actor) => {
90
+ const selectStaleCandidates = (bundle, items, actor, signals) => {
76
91
  const rows = [];
77
92
  for (const item of items) {
78
93
  const concept = bundle.concepts.get(item.id);
@@ -85,7 +100,11 @@ const selectStaleCandidates = (bundle, items, actor) => {
85
100
  status: status === "draft" ? "draft" : "stable",
86
101
  title: title ?? null,
87
102
  description: description ?? null,
88
- otherAttestations: (concept.frontmatter.verified ?? []).filter((entry) => entry.by !== actor).length
103
+ otherAttestations: (concept.frontmatter.verified ?? []).filter((entry) => entry.by !== actor).length,
104
+ integrity: signals.get(item.id)?.integrity ?? "none",
105
+ stale: signals.get(item.id)?.stale ?? false,
106
+ path: concept.path,
107
+ boundAt: boundAtOf(concept)
89
108
  });
90
109
  }
91
110
  return rows.toSorted((a, b) => a.type < b.type ? -1 : a.type > b.type ? 1 : a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
package/verify/splice.js CHANGED
@@ -49,8 +49,8 @@ const splice = (target, entry, newline) => {
49
49
  * Build the one edit for `target` (contract §6.1). Never calls a YAML
50
50
  * stringifier: the only syntax emitted is the indent, `<field>: `, the
51
51
  * preserved quote character (if any), and `newline`. `value` is already
52
- * encoded by the caller -- `Schema.encodeSync(Timestamp)`'d for `at`, the raw
53
- * lowercase hex digest for `body_sha256` (S-1: splice, never `YamlFormat.
52
+ * encoded by the caller -- `Schema.encodeSync(Timestamp)`'d for `at`, the only
53
+ * field (S-1: splice, never `YamlFormat.
54
54
  * modify` — it drops quote style and re-normalises line endings, V-12/V-15
55
55
  * violations `sync/generated.ts` cannot afford).
56
56
  *
@@ -71,27 +71,6 @@ const spliceGenerated = (target, value, newline, field = "at") => {
71
71
  }
72
72
  };
73
73
  /**
74
- * Build the edit(s) that write BOTH `generated.at` and `generated.
75
- * body_sha256` together (issue #19: `sync/generated.ts` never writes one
76
- * without the other). Each field's own `spliceGenerated` edit is used when
77
- * the two land at different offsets; when both are absent they resolve to
78
- * the identical `insertAfterLastKey` anchor (the mapping's last existing
79
- * key), and inserting two zero-length edits at the same offset is exactly
80
- * the "overlapping edits" case `MarkdownEdit.applyAll` treats as a
81
- * programmer error -- so that one case is merged into a single edit whose
82
- * content carries both lines, `at` first.
83
- *
84
- * @internal
85
- */
86
- const spliceGeneratedFields = (atTarget, bodySha256Target, encodedAt, bodySha256, newline) => {
87
- if (atTarget._tag === "insertAfterLastKey" && bodySha256Target._tag === "insertAfterLastKey" && atTarget.insertAt === bodySha256Target.insertAt) return [MarkdownEdit.make({
88
- offset: atTarget.insertAt,
89
- length: 0,
90
- content: `${atTarget.indent}at: ${encodedAt}${newline}${bodySha256Target.indent}body_sha256: ${bodySha256}${newline}`
91
- })];
92
- return [spliceGenerated(atTarget, encodedAt, newline, "at"), spliceGenerated(bodySha256Target, bodySha256, newline, "body_sha256")];
93
- };
94
- /**
95
74
  * Build the one edit for `target` (a top-level scalar key such as
96
75
  * `status`). Never calls a YAML stringifier: the only syntax emitted is
97
76
  * `<key>: `, the preserved quote character (if any), and `newline`.
@@ -123,7 +102,7 @@ const spliceTopLevelScalar = (target, key, value, newline) => {
123
102
  const spliceGeneratedBlock = (target, fields, newline) => MarkdownEdit.make({
124
103
  offset: target._tag === "absent" ? target.insertAt : target.start,
125
104
  length: target._tag === "absent" ? 0 : target.end - target.start,
126
- content: `generated:${newline} by: ${fields.by}${newline} at: ${fields.at}${newline} body_sha256: ${fields.bodySha256}${newline}`
105
+ content: `generated:${newline} by: ${fields.by}${newline} at: ${fields.at}${newline}`
127
106
  });
128
107
  /**
129
108
  * Issue #185: `okfit verify --stable` splices `status` and `verified` in one
@@ -131,7 +110,7 @@ const spliceGeneratedBlock = (target, fields, newline) => MarkdownEdit.make({
131
110
  * and when `verified` is absent it is appended as the last key, so both land
132
111
  * on the same offset when that anchor is the last key. `MarkdownEdit.applyAll`
133
112
  * rejects two zero-length inserts at one offset, the same case
134
- * `spliceGeneratedFields` merges, so this folds them into one edit, input
113
+ * `mergeSameOffset`'s own merge, so this folds them into one edit, input
135
114
  * order preserved.
136
115
  *
137
116
  * @internal
@@ -140,9 +119,9 @@ const mergeSameOffset = (edits) => {
140
119
  const out = [];
141
120
  for (const edit of edits) {
142
121
  const previous = out.at(-1);
143
- if (previous !== void 0 && previous.length === 0 && edit.length === 0 && previous.offset === edit.offset) out[out.length - 1] = MarkdownEdit.make({
122
+ if (previous !== void 0 && previous.length === 0 && previous.offset === edit.offset) out[out.length - 1] = MarkdownEdit.make({
144
123
  offset: edit.offset,
145
- length: 0,
124
+ length: edit.length,
146
125
  content: previous.content + edit.content
147
126
  });
148
127
  else out.push(edit);
@@ -150,15 +129,22 @@ const mergeSameOffset = (edits) => {
150
129
  return out;
151
130
  };
152
131
  /**
153
- * Fold a concept's `verified` edit and optional `status` edit into the ordered,
154
- * merged edit list both `okfit verify --stable` and `FrontmatterEdits` apply:
155
- * status first on equal offsets, so the merged insert emits `status:` before
156
- * `verified:`. The tie-break is by object identity -- the two edits are
157
- * otherwise indistinguishable.
132
+ * Fold a concept's `verified` edit and optional `status` and `integrity` edits
133
+ * into the ordered, merged edit list both `okfit verify` and `FrontmatterEdits`
134
+ * apply: on equal offsets `status:` comes first, then `verified:`, then
135
+ * `integrity:`. The tie-break is by object identity -- the edits are otherwise
136
+ * indistinguishable.
158
137
  *
159
138
  * @internal
160
139
  */
161
- const orderVerifyEdits = (verifiedEdit, statusEdit) => mergeSameOffset([verifiedEdit, ...statusEdit === void 0 ? [] : [statusEdit]].toSorted((a, b) => a.offset - b.offset || (a === statusEdit ? -1 : b === statusEdit ? 1 : 0)));
140
+ const orderVerifyEdits = (verifiedEdit, statusEdit, integrityEdit) => {
141
+ const rank = (edit) => edit === statusEdit ? 0 : edit === integrityEdit ? 2 : 1;
142
+ return mergeSameOffset([
143
+ verifiedEdit,
144
+ ...statusEdit === void 0 ? [] : [statusEdit],
145
+ ...integrityEdit === void 0 ? [] : [integrityEdit]
146
+ ].toSorted((a, b) => a.offset - b.offset || rank(a) - rank(b)));
147
+ };
162
148
 
163
149
  //#endregion
164
- export { mergeSameOffset, orderVerifyEdits, quoteLike, splice, spliceGenerated, spliceGeneratedBlock, spliceGeneratedFields, spliceTopLevelScalar };
150
+ export { mergeSameOffset, orderVerifyEdits, quoteLike, splice, spliceGenerated, spliceGeneratedBlock, spliceTopLevelScalar };
package/version.js CHANGED
@@ -11,7 +11,7 @@
11
11
  *
12
12
  * @public
13
13
  */
14
- const ENGINE_VERSION = "0.14.0";
14
+ const ENGINE_VERSION = "0.15.0";
15
15
 
16
16
  //#endregion
17
17
  export { ENGINE_VERSION };