@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/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { resolveBundleRoot, resolveProjectRoot } from "./config/anchor.js";
2
- import { ConfigMalformedError, ConfigPathNotFoundError, DocumentPathError, InitOverwriteError, QueryConceptNotFoundError, QuerySelectionError, QueryUnknownVocabularyError, SyncPlanStaleError, SyncPublicationConflictError, SyncStagedLogError, VerifyConceptNotFoundError, VerifySelectionError, VerifyUnsupportedFrontmatterError } from "./errors.js";
2
+ import { ConfigMalformedError, ConfigPathNotFoundError, DocumentPathError, InitOverwriteError, QueryConceptNotFoundError, QuerySelectionError, QueryUnknownVocabularyError, SyncPlanStaleError, SyncPublicationConflictError, SyncStagedLogError, VerifyConceptNotFoundError, VerifyNothingToRevokeError, VerifySelectionError, VerifyUnsupportedFrontmatterError } from "./errors.js";
3
3
  import { buildConfigLayer, provideConfig } from "./config/layer.js";
4
4
  import { DEFAULT_PROFILE_NAME, resolveProjectConfig } from "./config/resolve.js";
5
5
  import { runContext } from "./context/run.js";
@@ -11,25 +11,27 @@ import { OverlayDocuments, layerOverlayFileSystem, makeOverlayFileSystem } from
11
11
  import { provideDocuments, resolveDocumentPath } from "./overlay/documents.js";
12
12
  import { OkfitPlatform } from "./platform.js";
13
13
  import { ConceptQuery } from "./query/ConceptQuery.js";
14
- import { ContextEnvelope, ContextField, ContextFieldValue, ContextTag, ContextType, contextEnvelope } from "./render/context.js";
14
+ import { ContextEnvelope, ContextField, ContextFieldValue, ContextTag, ContextTrust, ContextType, contextEnvelope } from "./render/context.js";
15
15
  import { DistributionField } from "./render/distribution.js";
16
16
  import { forDiagnostics, tally } from "./render/exit.js";
17
17
  import { ENGINE_VERSION } from "./version.js";
18
18
  import { GraphEdgeEnvelope, GraphEnvelope, GraphNodeEnvelope, GraphSummary, graphEnvelope } from "./render/graph.js";
19
19
  import { collect, sort } from "./render/sort.js";
20
20
  import { JsonDiagnostic, JsonEnvelope, JsonErrorEnvelope, JsonSummary, json, jsonError } from "./render/json.js";
21
- import { ConceptSummary, QueryGetEnvelope, QueryLink, QueryListEnvelope, QueryNeighbor, QueryNeighborsEnvelope, queryGetEnvelope, queryListEnvelope, queryNeighborsEnvelope, toConceptSummary } from "./render/query.js";
21
+ import { ConceptSummary, QueryGetEnvelope, QueryLink, QueryListEnvelope, QueryNeighbor, QueryNeighborsEnvelope, TrustDrift, queryGetEnvelope, queryListEnvelope, queryNeighborsEnvelope, signalFor, toConceptSummary, toTrustDrift } from "./render/query.js";
22
22
  import { StaleEnvelope, StaleItem, StaleSummary, staleEnvelope } from "./render/stale.js";
23
23
  import { SkipReason, applySyncPlan, planSync, runSync } from "./sync/run.js";
24
24
  import { PublicationEnvelope, SyncEnvelope, SyncModeEnvelope, syncEnvelope } from "./render/sync.js";
25
- import { VerifyBatchEnvelope, VerifyEnvelope, verifyBatchEnvelope, verifyEnvelope } from "./render/verify.js";
25
+ import { RevokeEnvelope, VerifyBatchEnvelope, VerifyEnvelope, revokeEnvelope, verifyBatchEnvelope, verifyEnvelope } from "./render/verify.js";
26
26
  import { Now, run } from "./validate/run.js";
27
27
  import { conceptFor } from "./session/concept.js";
28
28
  import { withFallbackRange } from "./session/range.js";
29
29
  import { BundleSession } from "./session/BundleSession.js";
30
30
  import { runStale } from "./stale/run.js";
31
31
  import { NotAPublicationError, PublicationNotFoundError, stampPublication } from "./sync/publication.js";
32
+ import { runContextTrust } from "./trust/run.js";
33
+ import { changeSince } from "./verify/diff.js";
32
34
  import { resolveBatchTypes, selectAttestable, selectPickerCandidates, selectStaleCandidates } from "./verify/select.js";
33
- import { loadPickerCandidates, loadStaleCandidates, runVerify, runVerifyBatch, runVerifyIds } from "./verify/run.js";
35
+ import { inspectDrift, loadPickerCandidates, loadPreviews, loadStaleCandidates, runRevoke, runVerify, runVerifyBatch, runVerifyIds } from "./verify/run.js";
34
36
 
35
- export { BundleSession, CONFIG_RELATIVE_PATH, ConceptQuery, ConceptSummary, ConfigMalformedError, ConfigPathNotFoundError, ContextEnvelope, ContextField, ContextFieldValue, ContextTag, ContextType, DEFAULT_PROFILE_NAME, DistributionField, DocumentPathError, ENGINE_VERSION, ExternalReferences, FrontmatterEdits, GraphEdgeEnvelope, GraphEnvelope, GraphNodeEnvelope, GraphSummary, InitOverwriteError, JsonDiagnostic, JsonEnvelope, JsonErrorEnvelope, JsonSummary, NotAPublicationError, Now, OkfitPlatform, OverlayDocuments, PublicationEnvelope, PublicationNotFoundError, QueryConceptNotFoundError, QueryGetEnvelope, QueryLink, QueryListEnvelope, QueryNeighbor, QueryNeighborsEnvelope, QuerySelectionError, QueryUnknownVocabularyError, ReferenceCheck, ReferenceState, SkipReason, StaleEnvelope, StaleItem, StaleSummary, SyncEnvelope, SyncModeEnvelope, SyncPlanStaleError, SyncPublicationConflictError, SyncStagedLogError, UnsupportedFrontmatterError, VerifyBatchEnvelope, VerifyConceptNotFoundError, VerifyEnvelope, VerifySelectionError, VerifyUnsupportedFrontmatterError, applySyncPlan, buildConfigLayer, collect, conceptFor, configValue, contextEnvelope, files, forDiagnostics, graphEnvelope, json, jsonError, layerOverlayFileSystem, loadPickerCandidates, loadStaleCandidates, makeOverlayFileSystem, planSync, provideConfig, provideDocuments, queryGetEnvelope, queryListEnvelope, queryNeighborsEnvelope, resolveBatchTypes, resolveBundleRoot, resolveDocumentPath, resolveProjectConfig, resolveProjectRoot, run, runContext, runGraph, runStale, runSync, runVerify, runVerifyBatch, runVerifyIds, selectAttestable, selectPickerCandidates, selectStaleCandidates, sort, staleEnvelope, stampPublication, syncEnvelope, tally, targetPaths, toConceptSummary, verifyBatchEnvelope, verifyEnvelope, withFallbackRange };
37
+ export { BundleSession, CONFIG_RELATIVE_PATH, ConceptQuery, ConceptSummary, ConfigMalformedError, ConfigPathNotFoundError, ContextEnvelope, ContextField, ContextFieldValue, ContextTag, ContextTrust, ContextType, DEFAULT_PROFILE_NAME, DistributionField, DocumentPathError, ENGINE_VERSION, ExternalReferences, FrontmatterEdits, GraphEdgeEnvelope, GraphEnvelope, GraphNodeEnvelope, GraphSummary, InitOverwriteError, JsonDiagnostic, JsonEnvelope, JsonErrorEnvelope, JsonSummary, NotAPublicationError, Now, OkfitPlatform, OverlayDocuments, PublicationEnvelope, PublicationNotFoundError, QueryConceptNotFoundError, QueryGetEnvelope, QueryLink, QueryListEnvelope, QueryNeighbor, QueryNeighborsEnvelope, QuerySelectionError, QueryUnknownVocabularyError, ReferenceCheck, ReferenceState, RevokeEnvelope, SkipReason, StaleEnvelope, StaleItem, StaleSummary, SyncEnvelope, SyncModeEnvelope, SyncPlanStaleError, SyncPublicationConflictError, SyncStagedLogError, TrustDrift, UnsupportedFrontmatterError, VerifyBatchEnvelope, VerifyConceptNotFoundError, VerifyEnvelope, VerifyNothingToRevokeError, VerifySelectionError, VerifyUnsupportedFrontmatterError, applySyncPlan, buildConfigLayer, changeSince, collect, conceptFor, configValue, contextEnvelope, files, forDiagnostics, graphEnvelope, inspectDrift, json, jsonError, layerOverlayFileSystem, loadPickerCandidates, loadPreviews, loadStaleCandidates, makeOverlayFileSystem, planSync, provideConfig, provideDocuments, queryGetEnvelope, queryListEnvelope, queryNeighborsEnvelope, resolveBatchTypes, resolveBundleRoot, resolveDocumentPath, resolveProjectConfig, resolveProjectRoot, revokeEnvelope, run, runContext, runContextTrust, runGraph, runRevoke, runStale, runSync, runVerify, runVerifyBatch, runVerifyIds, selectAttestable, selectPickerCandidates, selectStaleCandidates, signalFor, sort, staleEnvelope, stampPublication, syncEnvelope, tally, targetPaths, toConceptSummary, toTrustDrift, verifyBatchEnvelope, verifyEnvelope, withFallbackRange };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@okfit/engine",
3
- "version": "0.14.0",
3
+ "version": "0.15.0",
4
4
  "private": false,
5
5
  "description": "The okfit engine: platform layer, config discovery, and the validate, verify, sync, init and context programs shared by the okfit CLI and MCP server.",
6
6
  "keywords": [
@@ -34,23 +34,24 @@
34
34
  "./package.json": "./package.json"
35
35
  },
36
36
  "dependencies": {
37
- "@effect/platform-node": "^4.0.2",
38
- "@effected/app": "^0.21.2",
39
- "@effected/config-file": "^0.14.2",
40
- "@effected/engine": "^0.4.0",
41
- "@effected/git": "^0.20.0",
42
- "@effected/glob": "^0.10.0",
43
- "@effected/jsonc": "^0.15.1",
44
- "@effected/markdown": "^0.15.1",
45
- "@effected/schemastore": "^0.21.3",
46
- "@effected/store": "^0.13.1",
47
- "@effected/toml": "^0.11.1",
48
- "@effected/walker": "^0.15.0",
49
- "@effected/xdg": "^0.9.0",
50
- "@effected/yaml": "^0.19.1",
51
- "@okfit/core": "0.9.2",
52
- "@okfit/profiles": "0.9.0",
53
- "effect": "^4.0.2"
37
+ "@effect/platform-node": "^4.0.3",
38
+ "@effect/platform-node-shared": "^4.0.3",
39
+ "@effected/app": "^0.22.0",
40
+ "@effected/config-file": "^0.15.0",
41
+ "@effected/engine": "^0.5.0",
42
+ "@effected/git": "^0.21.0",
43
+ "@effected/glob": "^0.11.0",
44
+ "@effected/jsonc": "^0.16.0",
45
+ "@effected/markdown": "^0.16.0",
46
+ "@effected/schemastore": "^0.22.0",
47
+ "@effected/store": "^0.14.0",
48
+ "@effected/toml": "^0.12.0",
49
+ "@effected/walker": "^0.16.0",
50
+ "@effected/xdg": "^0.10.0",
51
+ "@effected/yaml": "^0.20.0",
52
+ "@okfit/core": "0.10.0",
53
+ "@okfit/profiles": "0.10.0",
54
+ "effect": "^4.0.3"
54
55
  },
55
56
  "engines": {
56
57
  "node": ">=24.11.0"
@@ -28,8 +28,12 @@ const resolve = (bundle, rawId) => Effect.gen(function* () {
28
28
  * @public
29
29
  */
30
30
  const ConceptQuery = {
31
- /** Validates types then tags against config (first unknown fails), then filters and sorts by id. */
32
- list: (bundle, config, filter) => Effect.gen(function* () {
31
+ /**
32
+ * Validates types then tags against config (first unknown fails), then filters
33
+ * and sorts by id. `signals` is `Trust.signals(bundle, config, now)`; a concept with
34
+ * no signal is a caller defect.
35
+ */
36
+ list: (bundle, config, filter, signals) => Effect.gen(function* () {
33
37
  const declaredTypes = Object.keys(config.types ?? {}).toSorted();
34
38
  const declaredTags = Object.keys(config.tags ?? {}).toSorted();
35
39
  const types = filter.types ?? [];
@@ -45,13 +49,20 @@ const ConceptQuery = {
45
49
  valid: declaredTags
46
50
  }));
47
51
  const statuses = filter.statuses ?? [];
52
+ if (filter.verified !== void 0 || filter.drifted !== void 0 || filter.stale !== void 0) {
53
+ for (const concept of bundle.concepts.values()) if (!signals.has(concept.id)) return yield* Effect.die(/* @__PURE__ */ new Error(`ConceptQuery.list: no trust signal for concept "${concept.id}"`));
54
+ }
48
55
  return [...bundle.concepts.values()].filter((concept) => {
49
56
  if (types.length > 0 && !types.includes(concept.frontmatter.type)) return false;
50
57
  const tags = concept.frontmatter.tags ?? [];
51
58
  if (!requestedTags.every((tag) => tags.includes(tag))) return false;
52
59
  if (statuses.length > 0 && !statuses.includes(Derive.status(concept.frontmatter))) return false;
53
- if (filter.verified !== void 0) {
54
- if ((concept.frontmatter.verified ?? []).length > 0 !== filter.verified) return false;
60
+ const signal = signals.get(concept.id);
61
+ if (signal !== void 0) {
62
+ if (filter.verified === "current" && signal.integrity !== "current") return false;
63
+ if (filter.verified === "unverified" && signal.tier !== "unverified") return false;
64
+ if (filter.drifted !== void 0 && signal.integrity === "drifted" !== filter.drifted) return false;
65
+ if (filter.stale !== void 0 && signal.stale !== filter.stale) return false;
55
66
  }
56
67
  return true;
57
68
  }).toSorted(byId);
package/render/context.js CHANGED
@@ -43,6 +43,21 @@ const ContextTag = Schema.Struct({
43
43
  description: Schema.NullOr(Schema.String)
44
44
  });
45
45
  /**
46
+ * The `--trust` summary: how many concepts have drifted, are stale, or are
47
+ * unverified, with the first five drifted and stale ids (sorted). Counts
48
+ * overlap (a concept can be both drifted and stale).
49
+ *
50
+ * @public
51
+ */
52
+ const ContextTrust = Schema.Struct({
53
+ concepts: Schema.Int,
54
+ drifted: Schema.Int,
55
+ stale: Schema.Int,
56
+ unverified: Schema.Int,
57
+ drifted_ids: Schema.Array(Schema.String),
58
+ stale_ids: Schema.Array(Schema.String)
59
+ });
60
+ /**
46
61
  * M-15's envelope: schema 1, snake_case, orientation data only. Distinct
47
62
  * from `JsonEnvelope` (`render/json.ts`) — `context` never runs conformance
48
63
  * or lint checks, so there is no `diagnostics` array and no `exit_code`
@@ -83,7 +98,8 @@ const ContextEnvelope = Schema.Struct({
83
98
  index_exists: Schema.Boolean,
84
99
  actors: Schema.Struct({ agent: Schema.NullOr(Schema.String) }),
85
100
  types: Schema.Array(ContextType),
86
- tags: Schema.Array(ContextTag)
101
+ tags: Schema.Array(ContextTag),
102
+ trust: Schema.NullOr(ContextTrust)
87
103
  });
88
104
  /**
89
105
  * Build the envelope from the merged config. `types`/`tags` sort by `name`
@@ -123,8 +139,9 @@ const contextEnvelope = (input) => ({
123
139
  tags: Object.entries(input.config.tags ?? {}).map(([name, decl]) => ({
124
140
  name,
125
141
  description: decl.description ?? null
126
- })).toSorted((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0)
142
+ })).toSorted((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0),
143
+ trust: input.trust ?? null
127
144
  });
128
145
 
129
146
  //#endregion
130
- export { ContextEnvelope, ContextField, ContextFieldValue, ContextTag, ContextType, contextEnvelope };
147
+ export { ContextEnvelope, ContextField, ContextFieldValue, ContextTag, ContextTrust, ContextType, contextEnvelope };
package/render/query.js CHANGED
@@ -2,9 +2,22 @@ import { DistributionField } from "./distribution.js";
2
2
  import { ENGINE_VERSION } from "../version.js";
3
3
  import { Derive, GraphNodeKind, Status } from "@okfit/core";
4
4
  import { Schema } from "effect";
5
+ import { DriftReason } from "@okfit/profiles";
5
6
 
6
7
  //#region src/render/query.ts
7
- /** The seven-field shape every list-like query result carries (N-16). @public */
8
+ /**
9
+ * Why a human verification no longer binds, as the wire reports it. `edited_by`
10
+ * and `edited_at` are the latest human entry's actor and instant, `null` when
11
+ * the drift has no such entry to name.
12
+ *
13
+ * @public
14
+ */
15
+ const TrustDrift = Schema.Struct({
16
+ reason: DriftReason,
17
+ edited_by: Schema.NullOr(Schema.String),
18
+ edited_at: Schema.NullOr(Schema.String)
19
+ });
20
+ /** The ten-field shape every list-like query result carries: identity plus the trust signal (N-16). @public */
8
21
  const ConceptSummary = Schema.Struct({
9
22
  id: Schema.String,
10
23
  type: Schema.String,
@@ -12,18 +25,50 @@ const ConceptSummary = Schema.Struct({
12
25
  description: Schema.NullOr(Schema.String),
13
26
  status: Status,
14
27
  tags: Schema.Array(Schema.String),
15
- path: Schema.String
28
+ path: Schema.String,
29
+ tier: Schema.Literals([
30
+ "unverified",
31
+ "machine-confirmed",
32
+ "human-reviewed"
33
+ ]),
34
+ integrity: Schema.Literals([
35
+ "current",
36
+ "drifted",
37
+ "none"
38
+ ]),
39
+ stale: Schema.Boolean
16
40
  });
17
- /** Project one loaded concept into its summary. @public */
18
- const toConceptSummary = (concept) => ({
41
+ /** Project one loaded concept and its trust signal into its summary. @public */
42
+ const toConceptSummary = (concept, signal) => ({
19
43
  id: concept.id,
20
44
  type: concept.frontmatter.type,
21
45
  title: Derive.title(concept),
22
46
  description: concept.frontmatter.description ?? null,
23
47
  status: Derive.status(concept.frontmatter),
24
48
  tags: [...concept.frontmatter.tags ?? []],
25
- path: concept.path
49
+ path: concept.path,
50
+ tier: signal.tier,
51
+ integrity: signal.integrity,
52
+ stale: signal.stale
26
53
  });
54
+ /**
55
+ * The signal `Trust.signals` computed for a concept id. Every loaded concept has
56
+ * one, so a missing entry is a defect (the map and the bundle disagree), and this
57
+ * dies with a message naming the id rather than casting `undefined` through.
58
+ *
59
+ * @public
60
+ */
61
+ const signalFor = (signals, id) => {
62
+ const signal = signals.get(id);
63
+ if (signal === void 0) throw new Error(`no trust signal computed for concept "${id}"`);
64
+ return signal;
65
+ };
66
+ /** The wire drift of a signal, or `null` when its integrity is not drifted. @public */
67
+ const toTrustDrift = (signal) => signal.drift === void 0 ? null : {
68
+ reason: signal.drift.reason,
69
+ edited_by: signal.drift.editedBy ?? null,
70
+ edited_at: signal.drift.editedAt ?? null
71
+ };
27
72
  /** `okfit query list --format json`'s envelope, schema 1, snake_case. @public */
28
73
  const QueryListEnvelope = Schema.Struct({
29
74
  schema: Schema.Literal(1),
@@ -48,6 +93,7 @@ const QueryGetEnvelope = Schema.Struct({
48
93
  distribution: DistributionField,
49
94
  concept: Schema.Struct({
50
95
  ...ConceptSummary.fields,
96
+ drift: Schema.NullOr(TrustDrift),
51
97
  frontmatter: Schema.Record(Schema.String, Schema.Unknown),
52
98
  links: Schema.Array(QueryLink)
53
99
  })
@@ -85,6 +131,7 @@ const queryGetEnvelope = (input) => ({
85
131
  distribution: input.distribution ?? null,
86
132
  concept: {
87
133
  ...input.concept,
134
+ drift: input.drift,
88
135
  frontmatter: input.frontmatter,
89
136
  links: input.links
90
137
  }
@@ -101,4 +148,4 @@ const queryNeighborsEnvelope = (input) => ({
101
148
  });
102
149
 
103
150
  //#endregion
104
- export { ConceptSummary, QueryGetEnvelope, QueryLink, QueryListEnvelope, QueryNeighbor, QueryNeighborsEnvelope, queryGetEnvelope, queryListEnvelope, queryNeighborsEnvelope, toConceptSummary };
151
+ export { ConceptSummary, QueryGetEnvelope, QueryLink, QueryListEnvelope, QueryNeighbor, QueryNeighborsEnvelope, TrustDrift, queryGetEnvelope, queryListEnvelope, queryNeighborsEnvelope, signalFor, toConceptSummary, toTrustDrift };
package/render/sync.js CHANGED
@@ -9,6 +9,7 @@ const SyncModeEnvelope = Schema.Struct({
9
9
  selected: Schema.Boolean,
10
10
  written: Schema.Array(Schema.String),
11
11
  unchanged: Schema.Array(Schema.String),
12
+ migrated: Schema.Array(Schema.String),
12
13
  skipped: Schema.Array(Schema.Struct({
13
14
  id: Schema.String,
14
15
  reason: SkipReason
@@ -25,7 +26,7 @@ const PublicationEnvelope = Schema.Struct({
25
26
  written: Schema.Boolean,
26
27
  digests: Schema.Array(Schema.Struct({
27
28
  path: Schema.String,
28
- body_sha256: Schema.String
29
+ body: Schema.String
29
30
  }))
30
31
  });
31
32
  /**
@@ -57,12 +58,14 @@ const NOT_SELECTED = {
57
58
  selected: false,
58
59
  written: [],
59
60
  unchanged: [],
61
+ migrated: [],
60
62
  skipped: []
61
63
  };
62
64
  const toModeEnvelope = (mode) => ({
63
65
  selected: mode.selected,
64
66
  written: [...mode.written],
65
67
  unchanged: [...mode.unchanged],
68
+ migrated: [...mode.migrated],
66
69
  skipped: mode.skipped.map((entry) => ({
67
70
  id: entry.id,
68
71
  reason: entry.reason
package/render/verify.js CHANGED
@@ -2,6 +2,7 @@ import { DistributionField } from "./distribution.js";
2
2
  import { ENGINE_VERSION } from "../version.js";
3
3
  import { Status } from "@okfit/core";
4
4
  import { Schema } from "effect";
5
+ import { DriftReason } from "@okfit/profiles";
5
6
 
6
7
  //#region src/render/verify.ts
7
8
  /**
@@ -29,6 +30,8 @@ const VerifyEnvelope = Schema.Struct({
29
30
  from: Schema.NullOr(Status),
30
31
  to: Schema.Literals(["stable", "draft"])
31
32
  })),
33
+ /** Why the prior human verification no longer bound the concept; absent when it did not drift. */
34
+ prior_integrity: Schema.optionalKey(DriftReason),
32
35
  dry_run: Schema.Boolean,
33
36
  exit_code: Schema.Literal(0)
34
37
  });
@@ -52,6 +55,7 @@ const verifyEnvelope = (input) => ({
52
55
  at: input.at
53
56
  },
54
57
  status: input.status,
58
+ ...input.priorIntegrity === void 0 || input.priorIntegrity === null ? {} : { prior_integrity: input.priorIntegrity },
55
59
  dry_run: input.dryRun,
56
60
  exit_code: 0
57
61
  });
@@ -103,6 +107,44 @@ const verifyBatchEnvelope = (input) => ({
103
107
  dry_run: input.dryRun,
104
108
  exit_code: 0
105
109
  });
110
+ /**
111
+ * `okfit verify --revoke`'s success envelope, schema 1, snake_case. `removed`
112
+ * lists the `at` of every verification entry taken out (in list order);
113
+ * `binding_cleared` says whether `integrity.verified` went with them.
114
+ *
115
+ * @public
116
+ */
117
+ const RevokeEnvelope = Schema.Struct({
118
+ schema: Schema.Literal(1),
119
+ okfit_version: Schema.String,
120
+ engine_version: Schema.String,
121
+ distribution: DistributionField,
122
+ id: Schema.String,
123
+ path: Schema.String,
124
+ revoked_by: Schema.String,
125
+ removed: Schema.Array(Schema.String),
126
+ binding_cleared: Schema.Boolean,
127
+ dry_run: Schema.Boolean,
128
+ exit_code: Schema.Literal(0)
129
+ });
130
+ /**
131
+ * `path` is already the display form, as for {@link verifyEnvelope}.
132
+ *
133
+ * @public
134
+ */
135
+ const revokeEnvelope = (input) => ({
136
+ schema: 1,
137
+ okfit_version: input.okfitVersion,
138
+ engine_version: ENGINE_VERSION,
139
+ distribution: input.distribution ?? null,
140
+ id: input.id,
141
+ path: input.path,
142
+ revoked_by: input.by,
143
+ removed: input.removed,
144
+ binding_cleared: input.bindingCleared,
145
+ dry_run: input.dryRun,
146
+ exit_code: 0
147
+ });
106
148
 
107
149
  //#endregion
108
- export { VerifyBatchEnvelope, VerifyEnvelope, verifyBatchEnvelope, verifyEnvelope };
150
+ export { RevokeEnvelope, VerifyBatchEnvelope, VerifyEnvelope, revokeEnvelope, verifyBatchEnvelope, verifyEnvelope };
@@ -42,7 +42,8 @@ var BundleSession = class BundleSession extends Context.Service()("@okfit/engine
42
42
  const changed = yield* Ref.modify(published, (previous) => [diffDiagnostics(previous, next), next]);
43
43
  yield* Ref.set(loaded, Option.some({
44
44
  bundle: result.bundle,
45
- graph: Graph.fromBundle(result.bundle)
45
+ graph: Graph.fromBundle(result.bundle),
46
+ signals: result.signals
46
47
  }));
47
48
  return {
48
49
  changed,
@@ -58,6 +59,7 @@ var BundleSession = class BundleSession extends Context.Service()("@okfit/engine
58
59
  revalidate: (revalidate) => semaphore.withPermit(revalidateNow(revalidate)),
59
60
  bundle: () => Effect.map(Ref.get(loaded), Option.map((state) => state.bundle)),
60
61
  graph: () => Effect.map(Ref.get(loaded), Option.map((state) => state.graph)),
62
+ signals: () => Effect.map(Ref.get(loaded), Option.map((state) => state.signals)),
61
63
  config: () => options.config
62
64
  });
63
65
  });
package/sync/generated.js CHANGED
@@ -1,9 +1,11 @@
1
- import { detectNewline, locateGenerated, locateGeneratedBlock, locateGeneratedBodySha256, stripBom } from "../verify/locate.js";
2
- import { spliceGeneratedBlock, spliceGeneratedFields } from "../verify/splice.js";
1
+ import { detectNewline, locateGenerated, locateGeneratedBlock, stripBom } from "../verify/locate.js";
2
+ import { locateIntegrity, locateLegacyBodySha256, removeLine, spliceIntegrityGenerated } from "../verify/integrity.js";
3
+ import { mergeSameOffset, spliceGenerated, spliceGeneratedBlock } from "../verify/splice.js";
4
+ import { FrontmatterEdits } from "../edits/FrontmatterEdits.js";
3
5
  import { writeAtomic } from "./write.js";
4
6
  import { Timestamp } from "@okfit/core";
5
7
  import { Effect, FileSystem, Path, Schema } from "effect";
6
- import { Derivation } from "@okfit/profiles";
8
+ import { Derivation, PUBLICATION_TYPE } from "@okfit/profiles";
7
9
  import { MarkdownEdit } from "@effected/markdown";
8
10
 
9
11
  //#region src/sync/generated.ts
@@ -24,10 +26,30 @@ const GeneratedSkipReason = Schema.Literals([
24
26
  "dirty",
25
27
  "unborn",
26
28
  "generated-missing",
27
- "generated-unsupported"
29
+ "generated-unsupported",
30
+ "integrity-unsupported",
31
+ "renders-unsupported"
28
32
  ]);
29
33
  const encodeAt = Schema.encodeSync(Timestamp);
30
34
  /**
35
+ * For a Publication whose `renders` still carries a legacy `body_sha256`: the
36
+ * per-entry `renders[].body` to write (existing `body`, else the legacy 16-hex
37
+ * prefix), `undefined` for an entry with no legacy key. `undefined` overall when
38
+ * there is nothing to migrate.
39
+ */
40
+ const legacyRendersDigests = (concept) => {
41
+ if (concept.frontmatter.type !== PUBLICATION_TYPE) return void 0;
42
+ const renders = concept.frontmatter.raw.renders;
43
+ if (!Array.isArray(renders)) return void 0;
44
+ const digests = renders.map((entry) => {
45
+ if (typeof entry !== "object" || entry === null) return void 0;
46
+ const { body, body_sha256: legacy } = entry;
47
+ if (typeof legacy !== "string" || legacy === "") return void 0;
48
+ return typeof body === "string" && body !== "" ? body : legacy.slice(0, 16);
49
+ });
50
+ return digests.some((d) => d !== void 0) ? digests : void 0;
51
+ };
52
+ /**
31
53
  * Contract §6.2's algorithm, run once per `bundle.concepts` entry (S-22:
32
54
  * `index.md`/`log.md` are reserved files, never concepts, never seen here).
33
55
  * `options.provenance` is the single `Derivation.generatedAt` walk `runSync`
@@ -38,11 +60,14 @@ const encodeAt = Schema.encodeSync(Timestamp);
38
60
  * `runVerify`).
39
61
  *
40
62
  * Ordering (later tasks rely on it): (1) scope filter -> (2) digest match
41
- * against `generated.body_sha256` => `unchanged`, BEFORE any provenance
42
- * lookup -> (3) provenance absent => `Effect.die` (caller contract) -> (4)
43
- * `uncommitted` => skipped with its reason -> (5) no `generated` block:
44
- * `agent` unset => skipped `generated-missing`, else create -> (6) existing
45
- * block: splice `at` + `body_sha256` as today.
63
+ * against the recorded body digest (`integrity.generated.body`, else the
64
+ * legacy `generated.body_sha256` prefix) => `unchanged` (or a migrate-only
65
+ * write when a legacy line still exists), BEFORE any provenance lookup -> (3)
66
+ * provenance absent => `Effect.die` (caller contract) -> (4) `uncommitted` =>
67
+ * skipped with its reason -> (5) no `generated` block: `agent` unset =>
68
+ * skipped `generated-missing`, else create -> (6) existing block: splice `at`.
69
+ * Every write also sets `integrity.generated.body` (keeping `integrity.verified`)
70
+ * and removes a legacy `body_sha256` line.
46
71
  *
47
72
  * `locateGenerated`'s `YamlParseError` is folded into a defect here
48
73
  * (`Effect.orDie`), not widened into this function's typed error channel:
@@ -63,26 +88,34 @@ const syncGenerated = Effect.fn("okfit/sync/syncGenerated")(function* (bundle, o
63
88
  const { provenance, dryRun, agent, scope, pending } = options;
64
89
  const written = [];
65
90
  const unchanged = [];
91
+ const migrated = [];
66
92
  const skipped = [];
67
93
  for (const [id, concept] of bundle.concepts) {
68
94
  if (scope !== void 0 && !scope.has(id)) continue;
69
95
  const generated = concept.frontmatter.generated;
70
96
  const currentDigest = yield* Derivation.bodyDigest(concept.document.source);
71
- if (generated?.body_sha256 !== void 0 && generated.body_sha256 === currentDigest) {
97
+ const matches = Derivation.recordedBody(concept) === currentDigest;
98
+ const hasLegacy = generated?.body_sha256 !== void 0;
99
+ const legacyRenders = legacyRendersDigests(concept);
100
+ if (matches && !hasLegacy && legacyRenders === void 0) {
72
101
  unchanged.push(id);
73
102
  continue;
74
103
  }
75
- const derived = provenance.get(id);
76
- if (derived === void 0) return yield* Effect.die(/* @__PURE__ */ new Error(`syncGenerated: no provenance computed for concept ${id}`));
77
- if (derived._tag === "uncommitted") {
78
- skipped.push({
79
- id,
80
- reason: derived.reason
81
- });
82
- continue;
104
+ let encodedAt;
105
+ if (!matches) {
106
+ const derived = provenance.get(id);
107
+ if (derived === void 0) return yield* Effect.die(/* @__PURE__ */ new Error(`syncGenerated: no provenance computed for concept ${id}`));
108
+ if (derived._tag === "uncommitted") {
109
+ skipped.push({
110
+ id,
111
+ reason: derived.reason
112
+ });
113
+ continue;
114
+ }
115
+ encodedAt = encodeAt(derived.at);
83
116
  }
84
117
  const creating = generated === void 0 ? agent : void 0;
85
- if (generated === void 0 && creating === void 0) {
118
+ if (!matches && generated === void 0 && creating === void 0) {
86
119
  skipped.push({
87
120
  id,
88
121
  reason: "generated-missing"
@@ -93,49 +126,79 @@ const syncGenerated = Effect.fn("okfit/sync/syncGenerated")(function* (bundle, o
93
126
  const source = yield* fs.readFileString(absolutePath);
94
127
  const { text, bom } = stripBom(source);
95
128
  const newline = detectNewline(text);
96
- const encodedAt = encodeAt(derived.at);
97
- let edits;
98
- if (creating !== void 0) {
99
- const located = yield* locateGeneratedBlock(text).pipe(Effect.orDie);
100
- if (located._tag === "unsupported") {
101
- skipped.push({
102
- id,
103
- reason: "generated-unsupported"
104
- });
105
- continue;
129
+ const integrityLocated = yield* locateIntegrity(text).pipe(Effect.orDie);
130
+ if (integrityLocated._tag === "unsupported") {
131
+ skipped.push({
132
+ id,
133
+ reason: "integrity-unsupported"
134
+ });
135
+ continue;
136
+ }
137
+ const legacy = yield* locateLegacyBodySha256(text).pipe(Effect.orDie);
138
+ if (hasLegacy && legacy._tag === "none") {
139
+ skipped.push({
140
+ id,
141
+ reason: "generated-unsupported"
142
+ });
143
+ continue;
144
+ }
145
+ const edits = [];
146
+ if (encodedAt !== void 0) {
147
+ if (creating !== void 0) {
148
+ const located = yield* locateGeneratedBlock(text).pipe(Effect.orDie);
149
+ if (located._tag === "unsupported") {
150
+ skipped.push({
151
+ id,
152
+ reason: "generated-unsupported"
153
+ });
154
+ continue;
155
+ }
156
+ edits.push(spliceGeneratedBlock(located, {
157
+ by: creating,
158
+ at: encodedAt
159
+ }, newline));
160
+ } else {
161
+ const atLocated = yield* locateGenerated(text).pipe(Effect.orDie);
162
+ if (atLocated._tag === "unsupported") {
163
+ skipped.push({
164
+ id,
165
+ reason: "generated-unsupported"
166
+ });
167
+ continue;
168
+ }
169
+ edits.push(spliceGenerated(atLocated, encodedAt, newline, "at"));
106
170
  }
107
- edits = [spliceGeneratedBlock(located, {
108
- by: creating,
109
- at: encodedAt,
110
- bodySha256: currentDigest
111
- }, newline)];
112
- } else {
113
- const atLocated = yield* locateGenerated(text).pipe(Effect.orDie);
114
- const bodySha256Located = yield* locateGeneratedBodySha256(text).pipe(Effect.orDie);
115
- if (atLocated._tag === "unsupported" || bodySha256Located._tag === "unsupported") {
171
+ }
172
+ if (legacy._tag === "line") edits.push(removeLine(legacy));
173
+ if (legacyRenders !== void 0) {
174
+ const renderEdits = yield* FrontmatterEdits.rendersDigests(text, legacyRenders).pipe(Effect.catchTags({ UnsupportedFrontmatterError: () => Effect.succeed(void 0) }), Effect.orDie);
175
+ if (renderEdits === void 0) {
116
176
  skipped.push({
117
177
  id,
118
- reason: "generated-unsupported"
178
+ reason: "renders-unsupported"
119
179
  });
120
180
  continue;
121
181
  }
122
- edits = spliceGeneratedFields(atLocated, bodySha256Located, encodedAt, currentDigest, newline);
182
+ edits.push(...renderEdits);
123
183
  }
124
- const finalText = bom + MarkdownEdit.applyAll(text, edits);
125
- if (dryRun) {
126
- pending?.push({
127
- target: absolutePath,
128
- contents: finalText
129
- });
130
- written.push(id);
184
+ edits.push(spliceIntegrityGenerated(integrityLocated, text, currentDigest, newline));
185
+ const finalText = bom + MarkdownEdit.applyAll(text, mergeSameOffset(edits.toSorted((a, b) => a.offset - b.offset)));
186
+ if (finalText === source) {
187
+ unchanged.push(id);
131
188
  continue;
132
189
  }
133
- yield* writeAtomic(absolutePath, finalText);
134
- written.push(id);
190
+ if (legacy._tag === "line" || legacyRenders !== void 0) migrated.push(id);
191
+ if (!dryRun) yield* writeAtomic(absolutePath, finalText);
192
+ else pending?.push({
193
+ target: absolutePath,
194
+ contents: finalText
195
+ });
196
+ if (!matches) written.push(id);
135
197
  }
136
198
  return {
137
199
  written,
138
200
  unchanged,
201
+ migrated,
139
202
  skipped
140
203
  };
141
204
  });
@@ -36,7 +36,7 @@ var NotAPublicationError = class extends Schema.TaggedError()("NotAPublicationEr
36
36
  }
37
37
  };
38
38
  /**
39
- * Restamps one Publication's `renders[].body_sha256` digests from the current
39
+ * Restamps one Publication's `renders[].body` digests from the current
40
40
  * body of each rendered source concept, writing the Publication file
41
41
  * atomically unless `dryRun`. `written` is whether the text changed (so a
42
42
  * `dryRun` that would change the file reports `true` without writing).
@@ -72,11 +72,11 @@ const stampPublication = (options) => Effect.gen(function* () {
72
72
  });
73
73
  digests.push({
74
74
  path: entry.path,
75
- body_sha256: yield* Derivation.bodyDigest(source.document.source)
75
+ body: yield* Derivation.bodyDigest(source.document.source)
76
76
  });
77
77
  }
78
78
  const original = concept.document.source;
79
- const edits = yield* FrontmatterEdits.rendersDigests(original, digests.map((d) => d.body_sha256));
79
+ const edits = yield* FrontmatterEdits.rendersDigests(original, digests.map((d) => d.body));
80
80
  const next = MarkdownEdit.applyAll(original, edits);
81
81
  if (next === original) return {
82
82
  id,