@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.
- package/config/anchor.js +1 -1
- package/config/layer.js +1 -1
- package/edits/FrontmatterEdits.js +66 -18
- package/errors.js +102 -6
- package/index.d.ts +685 -53
- package/index.js +12 -6
- package/move/references.js +267 -0
- package/move/run.js +212 -0
- package/package.json +18 -18
- package/query/ConceptQuery.js +15 -4
- package/render/context.js +20 -3
- package/render/move.js +52 -0
- package/render/query.js +53 -6
- package/render/sync.js +4 -1
- package/render/verify.js +43 -1
- package/session/BundleSession.js +3 -1
- package/sync/generated.js +112 -49
- package/sync/index.js +4 -3
- package/sync/publication.js +3 -3
- package/sync/run.js +13 -4
- package/targets/inside.js +15 -0
- package/targets/resolve.js +146 -0
- package/trust/run.js +32 -0
- package/validate/run.js +8 -4
- package/verify/diff.js +63 -0
- package/verify/integrity.js +309 -0
- package/verify/locate.js +3 -10
- package/verify/revoke.js +101 -0
- package/verify/run.js +193 -21
- package/verify/select.js +30 -11
- package/verify/splice.js +20 -34
- package/version.js +1 -1
package/render/move.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { DistributionField } from "./distribution.js";
|
|
2
|
+
import { ENGINE_VERSION } from "../version.js";
|
|
3
|
+
import { Schema } from "effect";
|
|
4
|
+
|
|
5
|
+
//#region src/render/move.ts
|
|
6
|
+
/**
|
|
7
|
+
* `okfit mv`'s success envelope, schema 1, snake_case. `from`/`to` are bundle-relative paths, `path`
|
|
8
|
+
* the display form of the destination; `edits` lists every file that changes (post-move path) with
|
|
9
|
+
* its edit count, and `drifts` the ids whose current human verification the move invalidates.
|
|
10
|
+
*
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
const MoveEnvelope = Schema.Struct({
|
|
14
|
+
schema: Schema.Literal(1),
|
|
15
|
+
okfit_version: Schema.String,
|
|
16
|
+
engine_version: Schema.String,
|
|
17
|
+
distribution: DistributionField,
|
|
18
|
+
from: Schema.String,
|
|
19
|
+
to: Schema.String,
|
|
20
|
+
path: Schema.String,
|
|
21
|
+
dry_run: Schema.Boolean,
|
|
22
|
+
edits: Schema.Array(Schema.Struct({
|
|
23
|
+
path: Schema.String,
|
|
24
|
+
count: Schema.Number
|
|
25
|
+
})),
|
|
26
|
+
drifts: Schema.Array(Schema.String),
|
|
27
|
+
exit_code: Schema.Literal(0)
|
|
28
|
+
});
|
|
29
|
+
/**
|
|
30
|
+
* `path` is already the display form, as for the other envelope builders.
|
|
31
|
+
*
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
34
|
+
const moveEnvelope = (input) => ({
|
|
35
|
+
schema: 1,
|
|
36
|
+
okfit_version: input.okfitVersion,
|
|
37
|
+
engine_version: ENGINE_VERSION,
|
|
38
|
+
distribution: input.distribution ?? null,
|
|
39
|
+
from: input.from,
|
|
40
|
+
to: input.to,
|
|
41
|
+
path: input.path,
|
|
42
|
+
dry_run: input.dryRun,
|
|
43
|
+
edits: input.edits.map(({ path, count }) => ({
|
|
44
|
+
path,
|
|
45
|
+
count
|
|
46
|
+
})),
|
|
47
|
+
drifts: input.drifts,
|
|
48
|
+
exit_code: 0
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
//#endregion
|
|
52
|
+
export { MoveEnvelope, moveEnvelope };
|
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
|
-
/**
|
|
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
|
-
|
|
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 };
|
package/session/BundleSession.js
CHANGED
|
@@ -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,
|
|
2
|
-
import {
|
|
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.
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
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
|
-
|
|
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
|
-
|
|
76
|
-
if (
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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: "
|
|
178
|
+
reason: "renders-unsupported"
|
|
119
179
|
});
|
|
120
180
|
continue;
|
|
121
181
|
}
|
|
122
|
-
edits
|
|
182
|
+
edits.push(...renderEdits);
|
|
123
183
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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
|
-
|
|
134
|
-
|
|
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
|
});
|
package/sync/index.js
CHANGED
|
@@ -41,8 +41,9 @@ const writeOrCompare = Effect.fn("okfit/sync/index/writeOrCompare")(function* (t
|
|
|
41
41
|
});
|
|
42
42
|
/**
|
|
43
43
|
* Contract §7. Directories: the bundle root plus every directory in
|
|
44
|
-
* `
|
|
45
|
-
*
|
|
44
|
+
* `Derive.indexDirectories` -- each directory holding a concept and its
|
|
45
|
+
* ancestors, which a parent index links to (S-20, amended: an ancestor with
|
|
46
|
+
* no concept of its own still gets its index). A directory with an
|
|
46
47
|
* `index.md` but no concepts is left untouched (design §4: "nothing to
|
|
47
48
|
* derive") because such a directory is never a member of
|
|
48
49
|
* `bundle.directories` in the first place (`Bundle.load` only records a
|
|
@@ -60,7 +61,7 @@ const syncIndex = Effect.fn("okfit/sync/syncIndex")(function* (bundle, dryRun, p
|
|
|
60
61
|
subdirectories: childDirectoriesOf(bundle, "")
|
|
61
62
|
});
|
|
62
63
|
yield* writeOrCompare(path.join(bundle.root, "index.md"), "index.md", rootRendered, dryRun, written, unchanged, pending);
|
|
63
|
-
for (const dir of bundle
|
|
64
|
+
for (const dir of Derive.indexDirectories(bundle)) {
|
|
64
65
|
if (dir === "") continue;
|
|
65
66
|
const rendered = Derive.synthesizeIndex(bundle, dir);
|
|
66
67
|
yield* writeOrCompare(path.join(bundle.root, dir, "index.md"), `${dir}/index.md`, rendered, dryRun, written, unchanged, pending);
|
package/sync/publication.js
CHANGED
|
@@ -36,7 +36,7 @@ var NotAPublicationError = class extends Schema.TaggedError()("NotAPublicationEr
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
/**
|
|
39
|
-
* Restamps one Publication's `renders[].
|
|
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
|
-
|
|
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.
|
|
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,
|
package/sync/run.js
CHANGED
|
@@ -22,6 +22,8 @@ const SkipReason = Schema.Literals([
|
|
|
22
22
|
"unborn",
|
|
23
23
|
"generated-missing",
|
|
24
24
|
"generated-unsupported",
|
|
25
|
+
"integrity-unsupported",
|
|
26
|
+
"renders-unsupported",
|
|
25
27
|
"log-unparseable"
|
|
26
28
|
]);
|
|
27
29
|
/** A selected-`false` placeholder for a mode `--only` excluded from (contract §5). */
|
|
@@ -29,6 +31,7 @@ const UNSELECTED = {
|
|
|
29
31
|
selected: false,
|
|
30
32
|
written: [],
|
|
31
33
|
unchanged: [],
|
|
34
|
+
migrated: [],
|
|
32
35
|
skipped: []
|
|
33
36
|
};
|
|
34
37
|
/**
|
|
@@ -81,7 +84,7 @@ const planSync = Effect.fn("okfit/sync/planSync")(function* (options) {
|
|
|
81
84
|
for (const [id, concept] of bundle.concepts) {
|
|
82
85
|
const generated = concept.frontmatter.generated;
|
|
83
86
|
const digest = yield* Derivation.bodyDigest(concept.document.source);
|
|
84
|
-
const stampedAt =
|
|
87
|
+
const stampedAt = Derivation.recordedBody(concept) === digest ? generated?.at : void 0;
|
|
85
88
|
if (!(stampedAt === void 0 || options.modes.has("log") && wantsLogEntry(window, DateTime.formatIsoDate(stampedAt), Derive.title(concept)))) continue;
|
|
86
89
|
const derived = yield* Derivation.generatedAt({ file: `${bundle.root}/${concept.path}` });
|
|
87
90
|
walked.set(id, derived);
|
|
@@ -98,12 +101,18 @@ const planSync = Effect.fn("okfit/sync/planSync")(function* (options) {
|
|
|
98
101
|
...scope === void 0 ? {} : { scope }
|
|
99
102
|
})
|
|
100
103
|
} : UNSELECTED;
|
|
101
|
-
const index = options.modes.has("index") ?
|
|
102
|
-
|
|
104
|
+
const index = options.modes.has("index") ? {
|
|
105
|
+
...yield* syncIndex(bundle, true, pending),
|
|
106
|
+
migrated: []
|
|
107
|
+
} : UNSELECTED;
|
|
108
|
+
const log = options.modes.has("log") ? {
|
|
109
|
+
...yield* syncLog(bundle, walked, true, options.logSince, pending),
|
|
110
|
+
migrated: []
|
|
111
|
+
} : UNSELECTED;
|
|
103
112
|
let restage;
|
|
104
113
|
if (options.staged !== void 0 && repoRoot !== void 0) {
|
|
105
114
|
const path = yield* Path.Path;
|
|
106
|
-
const writtenIds = new Set(generated.written);
|
|
115
|
+
const writtenIds = /* @__PURE__ */ new Set([...generated.written, ...generated.migrated]);
|
|
107
116
|
const files = [...realPaths === void 0 ? [] : Array.from(realPaths.entries()).filter(([id]) => writtenIds.has(id)).map(([, real]) => real), ...index.written.map((relative) => path.join(bundle.root, relative))];
|
|
108
117
|
if (files.length > 0) restage = {
|
|
109
118
|
repoRoot,
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region src/targets/inside.ts
|
|
2
|
+
/**
|
|
3
|
+
* The posix path of `absolute` relative to `root` (`""` for the root itself), or `undefined` when it
|
|
4
|
+
* lies outside. Only a `..` segment escapes: a file named `..draft.md` is inside.
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
const relativeInside = (path, root, absolute) => {
|
|
9
|
+
const relative = path.relative(root, absolute);
|
|
10
|
+
if (relative === ".." || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) return void 0;
|
|
11
|
+
return relative.split(path.sep).join("/");
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
export { relativeInside };
|