@okfit/engine 0.14.1 → 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.
@@ -0,0 +1,101 @@
1
+ import { hasMergeKey, parseTopLevelMapping } from "./locate.js";
2
+ import { Effect } from "effect";
3
+ import { YamlAlias, YamlMap, YamlScalar, YamlSeq } from "@effected/yaml";
4
+
5
+ //#region src/verify/revoke.ts
6
+ const byActor = (actor) => (map) => map.items.some((entry) => entry.key instanceof YamlScalar && entry.key.value === "by" && entry.value instanceof YamlScalar && entry.value.value === actor);
7
+ /**
8
+ * Locate every top-level `verified` entry whose `by` is `actor`. See
9
+ * {@link VerifiedEntriesLocated}. Fails only when the frontmatter YAML is
10
+ * fatally unparseable.
11
+ *
12
+ * @internal
13
+ */
14
+ const locateVerifiedEntries = Effect.fn("okfit/verify/locateVerifiedEntries")(function* (source, actor) {
15
+ const parsed = yield* parseTopLevelMapping(source);
16
+ if ("_tag" in parsed) return parsed;
17
+ const { value, valueStart, contents } = parsed;
18
+ if (contents.style === "flow") return {
19
+ _tag: "unsupported",
20
+ shape: "flow-document"
21
+ };
22
+ const pair = contents.items.find((item) => item.key instanceof YamlScalar && item.key.value === "verified");
23
+ if (pair === void 0) return { _tag: "none" };
24
+ const node = pair.value;
25
+ if (node === null) return {
26
+ _tag: "unsupported",
27
+ shape: "empty"
28
+ };
29
+ if (node instanceof YamlAlias) return {
30
+ _tag: "unsupported",
31
+ shape: "alias"
32
+ };
33
+ if (hasMergeKey(node)) return {
34
+ _tag: "unsupported",
35
+ shape: "merge-key"
36
+ };
37
+ if (node instanceof YamlScalar) return {
38
+ _tag: "unsupported",
39
+ shape: "scalar"
40
+ };
41
+ const lineStart = (offset) => value.lastIndexOf("\n", offset - 1) + 1;
42
+ /** Just past the terminator of the line holding the node end `end`. */
43
+ const lineEnd = (end) => {
44
+ const before = value.lastIndexOf("\n", end - 1);
45
+ if (before !== -1 && /^[ \t]*$/u.test(value.slice(before + 1, end))) return before + 1;
46
+ const nl = value.indexOf("\n", end);
47
+ return nl === -1 ? value.length : nl + 1;
48
+ };
49
+ const keyStart = lineStart(pair.key.offset);
50
+ if (value.slice(keyStart, pair.key.offset).trim() !== "") return {
51
+ _tag: "unsupported",
52
+ shape: "not-a-mapping"
53
+ };
54
+ const keyLine = {
55
+ start: valueStart + keyStart,
56
+ end: valueStart + lineEnd(pair.key.offset + pair.key.length)
57
+ };
58
+ const whole = (tail) => ({
59
+ _tag: "entries",
60
+ removals: [{
61
+ start: keyLine.start,
62
+ end: valueStart + lineEnd(tail)
63
+ }],
64
+ removesAll: true,
65
+ keyLine
66
+ });
67
+ if (node instanceof YamlMap) return byActor(actor)(node) ? whole(node.offset + node.length) : { _tag: "none" };
68
+ if (!(node instanceof YamlSeq)) return {
69
+ _tag: "unsupported",
70
+ shape: "not-a-mapping"
71
+ };
72
+ if (node.style === "flow") return {
73
+ _tag: "unsupported",
74
+ shape: "flow-sequence"
75
+ };
76
+ const matching = node.items.filter((item) => item instanceof YamlMap && byActor(actor)(item));
77
+ if (matching.length === 0) return { _tag: "none" };
78
+ const last = node.items[node.items.length - 1];
79
+ if (matching.length === node.items.length && last !== void 0) return whole(last.offset + last.length);
80
+ const removals = [];
81
+ for (const item of matching) {
82
+ const start = lineStart(item.offset);
83
+ if (!/^ *- *$/u.test(value.slice(start, item.offset))) return {
84
+ _tag: "unsupported",
85
+ shape: "inline-item"
86
+ };
87
+ removals.push({
88
+ start: valueStart + start,
89
+ end: valueStart + lineEnd(item.offset + item.length)
90
+ });
91
+ }
92
+ return {
93
+ _tag: "entries",
94
+ removals,
95
+ removesAll: false,
96
+ keyLine
97
+ };
98
+ });
99
+
100
+ //#endregion
101
+ export { locateVerifiedEntries };
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,135 @@ 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
+ const prepareRevoke = Effect.fn("okfit/verify/prepareRevoke")(function* (bundle, rawId, actor) {
206
+ const { id, concept } = yield* resolveConcept(bundle, rawId);
207
+ const fs = yield* FileSystem.FileSystem;
208
+ const absolutePath = (yield* Path.Path).join(bundle.root, concept.path);
209
+ const source = new TextDecoder("utf-8", { ignoreBOM: true }).decode(yield* fs.readFile(absolutePath));
210
+ const { text, bom } = stripBom(source);
211
+ const entries = yield* locateVerifiedEntries(text, actor);
212
+ if (entries._tag === "unsupported") return yield* new VerifyUnsupportedFrontmatterError({
213
+ id,
214
+ shape: entries.shape,
215
+ key: "verified"
216
+ });
217
+ if (entries._tag === "none") return yield* new VerifyNothingToRevokeError({
218
+ id,
219
+ actor
220
+ });
221
+ const integrity = yield* locateIntegrity(text);
222
+ if (integrity._tag === "unsupported") return yield* new VerifyUnsupportedFrontmatterError({
223
+ id,
224
+ shape: integrity.shape,
225
+ key: "integrity"
226
+ });
227
+ const unbind = integrity._tag === "replace" && integrity.boundBy === actor ? removeIntegrityVerified(integrity, text) : { _tag: "none" };
228
+ if (unbind._tag === "unsupported") return yield* new VerifyUnsupportedFrontmatterError({
229
+ id,
230
+ shape: unbind.shape,
231
+ key: "integrity"
232
+ });
233
+ const edits = [...entries.removals.map((span) => MarkdownEdit.make({
234
+ offset: span.start,
235
+ length: span.end - span.start,
236
+ content: ""
237
+ })), ...unbind._tag === "edit" ? [unbind.edit] : []].toSorted((a, b) => a.offset - b.offset);
238
+ const finalText = bom + MarkdownEdit.applyAll(text, edits);
239
+ const removed = (concept.frontmatter.verified ?? []).filter((entry) => entry.by === actor).map((entry) => Schema.encodeSync(Timestamp)(entry.at));
240
+ return {
241
+ absolutePath,
242
+ finalText,
243
+ result: {
244
+ id,
245
+ bundleRoot: bundle.root,
246
+ conceptPath: concept.path,
247
+ by: actor,
248
+ removed,
249
+ bindingCleared: unbind._tag === "edit",
250
+ dryRun: false
251
+ }
252
+ };
253
+ });
254
+ /**
255
+ * `okfit verify --revoke`: removes every `verified` entry by the resolved
256
+ * human actor (the same git identity `verify` records) and, when
257
+ * `integrity.verified` is bound to that actor, that slot too, deleting the
258
+ * whole `integrity` block only when nothing else is left in it. Every cut is a
259
+ * byte-precise splice; an unsupported `verified` or `integrity` shape fails
260
+ * closed with the file untouched, and an actor with no entry fails
261
+ * `VerifyNothingToRevokeError`. Another actor's entries and binding are never
262
+ * touched, so they then read as `entry-superseded` or unbound by themselves.
263
+ *
264
+ * @internal
265
+ */
266
+ const runRevoke = Effect.fn("okfit/verify/runRevoke")(function* (options) {
267
+ const bundle = yield* Bundle.load({ root: options.bundleRoot });
268
+ const actor = yield* Derivation.verifier({
269
+ cwd: options.projectRoot,
270
+ config: options.config
271
+ });
272
+ const prepared = yield* prepareRevoke(bundle, options.id, actor);
273
+ if (!options.dryRun) yield* writeVerified(prepared.absolutePath, prepared.finalText);
274
+ return {
275
+ ...prepared.result,
276
+ dryRun: options.dryRun
165
277
  };
166
278
  });
167
279
  /**
280
+ * {@link runRevoke} for several concepts, all or nothing: every revoke is
281
+ * prepared before the first write, so one concept with nothing to revoke (or an
282
+ * unsupported shape, or an unknown id) fails the call with the tree untouched.
283
+ * Duplicate ids collapse to one. Results come back in the order given.
284
+ *
285
+ * @internal
286
+ */
287
+ const runRevokeIds = Effect.fn("okfit/verify/runRevokeIds")(function* (options) {
288
+ const bundle = yield* Bundle.load({ root: options.bundleRoot });
289
+ const actor = yield* Derivation.verifier({
290
+ cwd: options.projectRoot,
291
+ config: options.config
292
+ });
293
+ const prepared = /* @__PURE__ */ new Map();
294
+ for (const rawId of options.ids) {
295
+ const entry = yield* prepareRevoke(bundle, rawId, actor);
296
+ if (!prepared.has(entry.result.id)) prepared.set(entry.result.id, entry);
297
+ }
298
+ if (!options.dryRun) for (const entry of prepared.values()) yield* writeVerified(entry.absolutePath, entry.finalText);
299
+ return [...prepared.values()].map((entry) => ({
300
+ ...entry.result,
301
+ dryRun: options.dryRun
302
+ }));
303
+ });
304
+ /**
168
305
  * Issue #138. Attests every concept selected by `options.types` (or, when
169
306
  * 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
307
+ * is not a draft, is not deprecated (#143) and whose `verified` entry by the
308
+ * resolved actor does not already bind its current content (`Trust.signals`). Every candidate is located FIRST -- an unsupported
172
309
  * `verified` shape on any one of them fails the whole batch with nothing
173
310
  * written, mirroring `runVerify`'s own fail-closed rule at batch scale.
174
311
  *
@@ -177,13 +314,13 @@ const runVerify = Effect.fn("okfit/verify/runVerify")(function* (options) {
177
314
  const runVerifyBatch = Effect.fn("okfit/verify/runVerifyBatch")(function* (options) {
178
315
  const bundle = yield* Bundle.load({ root: options.bundleRoot });
179
316
  const types = yield* resolveBatchTypes(options.config, options.types);
180
- const actor = yield* Derivation.generatedBy({
181
- writer: "human",
317
+ const actor = yield* Derivation.verifier({
182
318
  cwd: options.projectRoot,
183
319
  config: options.config
184
320
  });
185
321
  const at = Schema.encodeSync(Timestamp)(options.at);
186
- const selection = selectAttestable(bundle, types, actor);
322
+ const signals = yield* Trust.signals(bundle, options.config, options.at);
323
+ const selection = selectAttestable(bundle, types, actor, signals);
187
324
  const prepared = [];
188
325
  for (const concept of selection.candidates) prepared.push({
189
326
  id: concept.id,
@@ -218,8 +355,7 @@ const runVerifyBatch = Effect.fn("okfit/verify/runVerifyBatch")(function* (optio
218
355
  */
219
356
  const runVerifyIds = Effect.fn("okfit/verify/runVerifyIds")(function* (options) {
220
357
  const bundle = yield* Bundle.load({ root: options.bundleRoot });
221
- const actor = yield* Derivation.generatedBy({
222
- writer: "human",
358
+ const actor = yield* Derivation.verifier({
223
359
  cwd: options.projectRoot,
224
360
  config: options.config
225
361
  });
@@ -253,6 +389,11 @@ const runVerifyIds = Effect.fn("okfit/verify/runVerifyIds")(function* (options)
253
389
  skipped: []
254
390
  };
255
391
  });
392
+ /** The rows with `path` joined onto the bundle root, so the picker's callers get absolute file paths. */
393
+ const absolutePaths = (rows, path, root) => rows.map((row) => ({
394
+ ...row,
395
+ path: path.join(root, row.path)
396
+ }));
256
397
  /**
257
398
  * The interactive verify picker's starting point: loads the bundle, resolves
258
399
  * the human actor from git exactly as {@link runVerify} does, and selects the
@@ -262,14 +403,15 @@ const runVerifyIds = Effect.fn("okfit/verify/runVerifyIds")(function* (options)
262
403
  */
263
404
  const loadPickerCandidates = Effect.fn("okfit/verify/loadPickerCandidates")(function* (options) {
264
405
  const bundle = yield* Bundle.load({ root: options.bundleRoot });
265
- const by = yield* Derivation.generatedBy({
266
- writer: "human",
406
+ const by = yield* Derivation.verifier({
267
407
  cwd: options.projectRoot,
268
408
  config: options.config
269
409
  });
410
+ const signals = yield* Trust.signals(bundle, options.config, yield* DateTime.now);
411
+ const path = yield* Path.Path;
270
412
  return {
271
413
  by,
272
- candidates: selectPickerCandidates(bundle, options.config, by)
414
+ candidates: absolutePaths(selectPickerCandidates(bundle, options.config, by, signals), path, bundle.root)
273
415
  };
274
416
  });
275
417
  /**
@@ -281,16 +423,46 @@ const loadPickerCandidates = Effect.fn("okfit/verify/loadPickerCandidates")(func
281
423
  */
282
424
  const loadStaleCandidates = Effect.fn("okfit/verify/loadStaleCandidates")(function* (options) {
283
425
  const bundle = yield* Bundle.load({ root: options.bundleRoot });
284
- const by = yield* Derivation.generatedBy({
285
- writer: "human",
426
+ const by = yield* Derivation.verifier({
286
427
  cwd: options.projectRoot,
287
428
  config: options.config
288
429
  });
430
+ const signals = yield* Trust.signals(bundle, options.config, options.now);
431
+ const path = yield* Path.Path;
289
432
  return {
290
433
  by,
291
- candidates: selectStaleCandidates(bundle, Derive.staleReport(bundle, options.now), by)
434
+ candidates: absolutePaths(selectStaleCandidates(bundle, Derive.staleReport(bundle, options.now), by, signals), path, bundle.root)
292
435
  };
293
436
  });
437
+ /**
438
+ * The verify picker's diff previews: for each drifted candidate, in candidate
439
+ * order and one at a time, what changed in its file since its verification was
440
+ * bound ({@link changeSince}). A candidate with no binding is `no-baseline`
441
+ * `unbound` without touching git, and a git failure reading the history is
442
+ * `no-baseline` `not-a-repository`, so a preview never fails the picker. Rows
443
+ * that are not drifted get no entry. Reads only.
444
+ *
445
+ * @public
446
+ */
447
+ const loadPreviews = Effect.fn("okfit/verify/loadPreviews")(function* (candidates) {
448
+ const previews = /* @__PURE__ */ new Map();
449
+ for (const candidate of candidates) {
450
+ if (candidate.integrity !== "drifted") continue;
451
+ const at = candidate.boundAt === null ? void 0 : DateTime.make(candidate.boundAt);
452
+ const preview = at === void 0 || Option.isNone(at) ? {
453
+ _tag: "no-baseline",
454
+ reason: "unbound"
455
+ } : yield* changeSince({
456
+ file: candidate.path,
457
+ at: DateTime.toUtc(at.value)
458
+ }).pipe(Effect.catchTag("GitCommandError", () => Effect.succeed({
459
+ _tag: "no-baseline",
460
+ reason: "not-a-repository"
461
+ })));
462
+ previews.set(candidate.id, preview);
463
+ }
464
+ return previews;
465
+ });
294
466
 
295
467
  //#endregion
296
- export { loadPickerCandidates, loadStaleCandidates, runVerify, runVerifyBatch, runVerifyIds };
468
+ export { inspectDrift, loadPickerCandidates, loadPreviews, loadStaleCandidates, runRevoke, runRevokeIds, 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.1";
14
+ const ENGINE_VERSION = "0.16.0";
15
15
 
16
16
  //#endregion
17
17
  export { ENGINE_VERSION };