@okfit/engine 0.13.1 → 0.14.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/errors.js +22 -3
- package/index.d.ts +114 -11
- package/index.js +5 -5
- package/package.json +3 -3
- package/sync/generated.js +5 -1
- package/sync/index.js +8 -4
- package/sync/log.js +13 -7
- package/sync/run.js +81 -20
- package/verify/locate.js +19 -1
- package/verify/run.js +54 -11
- package/verify/select.js +28 -1
- package/verify/splice.js +13 -17
- package/version.js +1 -1
package/errors.js
CHANGED
|
@@ -72,7 +72,11 @@ var VerifyConceptNotFoundError = class extends Schema.TaggedError()("VerifyConce
|
|
|
72
72
|
var VerifyUnsupportedFrontmatterError = class extends Schema.TaggedError()("VerifyUnsupportedFrontmatterError", {
|
|
73
73
|
id: Schema.String,
|
|
74
74
|
shape: Schema.String,
|
|
75
|
-
key: Schema.optionalKey(Schema.Literals([
|
|
75
|
+
key: Schema.optionalKey(Schema.Literals([
|
|
76
|
+
"verified",
|
|
77
|
+
"status",
|
|
78
|
+
"stale_after"
|
|
79
|
+
]))
|
|
76
80
|
}) {
|
|
77
81
|
[Runtime.errorExitCode] = 3;
|
|
78
82
|
get message() {
|
|
@@ -121,6 +125,19 @@ var SyncStagedLogError = class extends Schema.TaggedError()("SyncStagedLogError"
|
|
|
121
125
|
}
|
|
122
126
|
};
|
|
123
127
|
/**
|
|
128
|
+
* `applySyncPlan` found a file its plan would write changed since `planSync`
|
|
129
|
+
* read it, so applying the plan would overwrite an edit the plan never showed.
|
|
130
|
+
* Nothing was written. `paths` are the changed targets (absolute); re-run sync.
|
|
131
|
+
*
|
|
132
|
+
* @public
|
|
133
|
+
*/
|
|
134
|
+
var SyncPlanStaleError = class extends Schema.TaggedError()("SyncPlanStaleError", { paths: Schema.Array(Schema.String) }) {
|
|
135
|
+
[Runtime.errorExitCode] = 3;
|
|
136
|
+
get message() {
|
|
137
|
+
return `changed since the sync plan was made: ${this.paths.join(", ")}; nothing was written, re-run sync`;
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
/**
|
|
124
141
|
* `okfit sync --publication` runs nothing else, so combining it with a mode
|
|
125
142
|
* or selection flag (`--only`, `--staged`, `--since`) is a usage error. Exit 64.
|
|
126
143
|
*
|
|
@@ -143,7 +160,8 @@ var VerifySelectionError = class extends Schema.TaggedError()("VerifySelectionEr
|
|
|
143
160
|
"id-and-batch",
|
|
144
161
|
"unknown-type",
|
|
145
162
|
"status-conflict",
|
|
146
|
-
"status-and-batch"
|
|
163
|
+
"status-and-batch",
|
|
164
|
+
"dry-run-needs-verify"
|
|
147
165
|
]),
|
|
148
166
|
detail: Schema.optionalKey(Schema.String)
|
|
149
167
|
}) {
|
|
@@ -152,6 +170,7 @@ var VerifySelectionError = class extends Schema.TaggedError()("VerifySelectionEr
|
|
|
152
170
|
if (this.reason === "no-selection") return "verify needs a concept id, --all, or --type <Type> (run in a terminal to pick interactively)";
|
|
153
171
|
if (this.reason === "id-and-batch") return "verify takes either a concept id or --all/--type, not both";
|
|
154
172
|
if (this.reason === "status-conflict") return "verify takes --stable or --draft, not both";
|
|
173
|
+
if (this.reason === "dry-run-needs-verify") return "--dry-run needs --verify; bare okfit stale writes nothing";
|
|
155
174
|
if (this.reason === "status-and-batch") return "--stable and --draft need a concept id; batch mode never changes status";
|
|
156
175
|
return `type "${this.detail ?? ""}" is not declared in the config`;
|
|
157
176
|
}
|
|
@@ -234,4 +253,4 @@ var QuerySelectionError = class extends Schema.TaggedError()("QuerySelectionErro
|
|
|
234
253
|
};
|
|
235
254
|
|
|
236
255
|
//#endregion
|
|
237
|
-
export { ConfigMalformedError, ConfigPathNotFoundError, DocumentPathError, InitOverwriteError, QueryConceptNotFoundError, QuerySelectionError, QueryUnknownVocabularyError, SyncPublicationConflictError, SyncStagedLogError, VerifyConceptNotFoundError, VerifySelectionError, VerifyUnsupportedFrontmatterError };
|
|
256
|
+
export { ConfigMalformedError, ConfigPathNotFoundError, DocumentPathError, InitOverwriteError, QueryConceptNotFoundError, QuerySelectionError, QueryUnknownVocabularyError, SyncPlanStaleError, SyncPublicationConflictError, SyncStagedLogError, VerifyConceptNotFoundError, VerifySelectionError, VerifyUnsupportedFrontmatterError };
|
package/index.d.ts
CHANGED
|
@@ -126,7 +126,7 @@ export declare class VerifyConceptNotFoundError extends VerifyConceptNotFoundErr
|
|
|
126
126
|
declare const VerifyUnsupportedFrontmatterError_base: Schema.Class<VerifyUnsupportedFrontmatterError, Schema.TaggedStruct<"VerifyUnsupportedFrontmatterError", {
|
|
127
127
|
readonly id: Schema.String;
|
|
128
128
|
readonly shape: Schema.String;
|
|
129
|
-
readonly key: Schema.optionalKey<Schema.Literals<readonly ["verified", "status"]>>;
|
|
129
|
+
readonly key: Schema.optionalKey<Schema.Literals<readonly ["verified", "status", "stale_after"]>>;
|
|
130
130
|
}>, import("effect/Cause").YieldableError>;
|
|
131
131
|
/**
|
|
132
132
|
* V-14: fail closed on a `verified` (or, under `--stable`/`--draft`, `status`)
|
|
@@ -173,6 +173,20 @@ export declare class SyncStagedLogError extends SyncStagedLogError_base {
|
|
|
173
173
|
readonly [Runtime.errorExitCode] = 64;
|
|
174
174
|
get message(): string;
|
|
175
175
|
}
|
|
176
|
+
declare const SyncPlanStaleError_base: Schema.Class<SyncPlanStaleError, Schema.TaggedStruct<"SyncPlanStaleError", {
|
|
177
|
+
readonly paths: Schema.$Array<Schema.String>;
|
|
178
|
+
}>, import("effect/Cause").YieldableError>;
|
|
179
|
+
/**
|
|
180
|
+
* `applySyncPlan` found a file its plan would write changed since `planSync`
|
|
181
|
+
* read it, so applying the plan would overwrite an edit the plan never showed.
|
|
182
|
+
* Nothing was written. `paths` are the changed targets (absolute); re-run sync.
|
|
183
|
+
*
|
|
184
|
+
* @public
|
|
185
|
+
*/
|
|
186
|
+
export declare class SyncPlanStaleError extends SyncPlanStaleError_base {
|
|
187
|
+
readonly [Runtime.errorExitCode] = 3;
|
|
188
|
+
get message(): string;
|
|
189
|
+
}
|
|
176
190
|
declare const SyncPublicationConflictError_base: Schema.Class<SyncPublicationConflictError, Schema.TaggedStruct<"SyncPublicationConflictError", {
|
|
177
191
|
readonly flags: Schema.$Array<Schema.String>;
|
|
178
192
|
}>, import("effect/Cause").YieldableError>;
|
|
@@ -187,7 +201,7 @@ export declare class SyncPublicationConflictError extends SyncPublicationConflic
|
|
|
187
201
|
get message(): string;
|
|
188
202
|
}
|
|
189
203
|
declare const VerifySelectionError_base: Schema.Class<VerifySelectionError, Schema.TaggedStruct<"VerifySelectionError", {
|
|
190
|
-
readonly reason: Schema.Literals<readonly ["no-selection", "id-and-batch", "unknown-type", "status-conflict", "status-and-batch"]>;
|
|
204
|
+
readonly reason: Schema.Literals<readonly ["no-selection", "id-and-batch", "unknown-type", "status-conflict", "status-and-batch", "dry-run-needs-verify"]>;
|
|
191
205
|
readonly detail: Schema.optionalKey<Schema.String>;
|
|
192
206
|
}>, import("effect/Cause").YieldableError>;
|
|
193
207
|
/**
|
|
@@ -1436,6 +1450,22 @@ export declare const staleEnvelope: (input: {
|
|
|
1436
1450
|
readonly distribution?: Distribution;
|
|
1437
1451
|
}) => StaleEnvelope;
|
|
1438
1452
|
//#endregion
|
|
1453
|
+
//#region src/sync/write.d.ts
|
|
1454
|
+
/**
|
|
1455
|
+
* A write a sync mode would perform: the plan half of plan/apply. `target` is
|
|
1456
|
+
* the absolute path handed to `writeAtomic`; `contents` the full text. `before`
|
|
1457
|
+
* is what `planSync` read from `target` while planning (`null` = the file was
|
|
1458
|
+
* absent); `applySyncPlan` refuses to run when a target no longer matches it.
|
|
1459
|
+
* A write without `before` is applied unchecked.
|
|
1460
|
+
*
|
|
1461
|
+
* @public
|
|
1462
|
+
*/
|
|
1463
|
+
interface PendingWrite {
|
|
1464
|
+
readonly target: string;
|
|
1465
|
+
readonly contents: string;
|
|
1466
|
+
readonly before?: string | null;
|
|
1467
|
+
}
|
|
1468
|
+
//#endregion
|
|
1439
1469
|
//#region src/sync/run.d.ts
|
|
1440
1470
|
/** The three families `okfit sync` regenerates (contract §5). @public */
|
|
1441
1471
|
type SyncMode = "generated" | "index" | "log";
|
|
@@ -1485,17 +1515,59 @@ interface SyncResult {
|
|
|
1485
1515
|
readonly log: SyncModeResult;
|
|
1486
1516
|
}
|
|
1487
1517
|
/**
|
|
1488
|
-
*
|
|
1489
|
-
* `
|
|
1490
|
-
*
|
|
1491
|
-
*
|
|
1492
|
-
* index, log — regardless of `--only`'s own occurrence order, so a
|
|
1493
|
-
* generated write never invalidates an index or log rendered in the same
|
|
1494
|
-
* run (design §2).
|
|
1518
|
+
* What {@link planSync} computed and {@link applySyncPlan} will perform.
|
|
1519
|
+
* `result` is the exact dry-run report (`dryRun: true`); `pending` holds the
|
|
1520
|
+
* file writes behind it, in the fixed generated, index, log order; `restage`
|
|
1521
|
+
* (a `--staged` run only) is the `git add` that follows them.
|
|
1495
1522
|
*
|
|
1496
1523
|
* @public
|
|
1497
1524
|
*/
|
|
1498
|
-
|
|
1525
|
+
interface SyncPlan {
|
|
1526
|
+
readonly result: SyncResult;
|
|
1527
|
+
readonly pending: ReadonlyArray<PendingWrite>;
|
|
1528
|
+
readonly restage?: {
|
|
1529
|
+
readonly repoRoot: string;
|
|
1530
|
+
readonly files: ReadonlyArray<string>;
|
|
1531
|
+
};
|
|
1532
|
+
}
|
|
1533
|
+
/**
|
|
1534
|
+
* Contract §5's six-step algorithm, computed without writing: one
|
|
1535
|
+
* `Bundle.load`, then a lazy `Derivation.generatedAt` walk shared by the
|
|
1536
|
+
* generated and log modes (issue #21) -- computed only for a concept that
|
|
1537
|
+
* still needs one, not for every concept -- then the three modes in a FIXED
|
|
1538
|
+
* order -- generated, index, log -- regardless of `--only`'s own occurrence
|
|
1539
|
+
* order. Every mode runs as a dry run and records its writes in
|
|
1540
|
+
* {@link SyncPlan.pending}; no mode reads a file another mode writes (generated
|
|
1541
|
+
* reads concept files, index reads `index.md`s, log reads `log.md`), which is
|
|
1542
|
+
* what makes the dry-run report exact and the deferred apply safe (design §2).
|
|
1543
|
+
* `options.dryRun` is ignored here: a plan never writes.
|
|
1544
|
+
*
|
|
1545
|
+
* @public
|
|
1546
|
+
*/
|
|
1547
|
+
export declare const planSync: (options: SyncOptions) => Effect.Effect<SyncPlan, BundleLoadError | GeneratedAtError | SyncStagedLogError, Git | GitHistory | FileSystem.FileSystem | Path.Path | Crypto.Crypto>;
|
|
1548
|
+
/**
|
|
1549
|
+
* Performs exactly the writes a {@link SyncPlan} recorded (atomically, in plan
|
|
1550
|
+
* order), then the `--staged` re-add, and returns the non-dry-run
|
|
1551
|
+
* {@link SyncResult}. The bundle is not reloaded: the plan is applied as
|
|
1552
|
+
* computed. Before writing anything it re-reads every target and fails
|
|
1553
|
+
* {@link SyncPlanStaleError} (writing nothing) if one differs from what
|
|
1554
|
+
* {@link planSync} saw, so the run writes exactly the plan it showed.
|
|
1555
|
+
*
|
|
1556
|
+
* @public
|
|
1557
|
+
*/
|
|
1558
|
+
export declare const applySyncPlan: (plan: SyncPlan) => Effect.Effect<{
|
|
1559
|
+
bundleRoot: string;
|
|
1560
|
+
generated: SyncModeResult;
|
|
1561
|
+
index: SyncModeResult;
|
|
1562
|
+
log: SyncModeResult;
|
|
1563
|
+
dryRun: false;
|
|
1564
|
+
}, import("@effected/git").GitCommandError | import("@effected/git").NotARepositoryError | import("effect/PlatformError").PlatformError | SyncPlanStaleError | import("@effected/git").UnknownRefError, FileSystem.FileSystem | Git | Path.Path>;
|
|
1565
|
+
/**
|
|
1566
|
+
* `planSync`, then `applySyncPlan` unless `dryRun`.
|
|
1567
|
+
*
|
|
1568
|
+
* @public
|
|
1569
|
+
*/
|
|
1570
|
+
export declare const runSync: (options: SyncOptions) => Effect.Effect<SyncResult, BundleLoadError | GeneratedAtError | SyncStagedLogError | SyncPlanStaleError, Git | GitHistory | FileSystem.FileSystem | Path.Path | Crypto.Crypto>;
|
|
1499
1571
|
//#endregion
|
|
1500
1572
|
//#region src/render/sync.d.ts
|
|
1501
1573
|
/** @public */
|
|
@@ -1657,6 +1729,16 @@ interface PickerCandidate {
|
|
|
1657
1729
|
* @public
|
|
1658
1730
|
*/
|
|
1659
1731
|
export declare const selectPickerCandidates: (bundle: LoadedBundle, config: OkfitConfig, actor: string) => ReadonlyArray<PickerCandidate>;
|
|
1732
|
+
/**
|
|
1733
|
+
* Issue #228: the picker rows for `okfit stale --verify`: one per stale item,
|
|
1734
|
+
* any type, deprecated concepts excluded. Unlike {@link selectPickerCandidates}
|
|
1735
|
+
* the actor's own attestation does not exclude a row, because re-attesting is
|
|
1736
|
+
* the point; `otherAttestations` still counts only other actors. Sorted by
|
|
1737
|
+
* type, then id.
|
|
1738
|
+
*
|
|
1739
|
+
* @public
|
|
1740
|
+
*/
|
|
1741
|
+
export declare const selectStaleCandidates: (bundle: LoadedBundle, items: ReadonlyArray<StaleConcept>, actor: string) => ReadonlyArray<PickerCandidate>;
|
|
1660
1742
|
/**
|
|
1661
1743
|
* The batch type-resolution rule shared by `runVerifyBatch` and any future
|
|
1662
1744
|
* interactive picker: explicit `types` must each be declared in
|
|
@@ -2177,6 +2259,14 @@ interface VerifyIdsOptions {
|
|
|
2177
2259
|
readonly ids: ReadonlyArray<string>;
|
|
2178
2260
|
/** Also set `status: stable` on every selected concept whose status is `draft`. Default `false`. */
|
|
2179
2261
|
readonly promote?: boolean;
|
|
2262
|
+
/**
|
|
2263
|
+
* Issue #228: also roll each selected concept's existing `stale_after`
|
|
2264
|
+
* forward to `Derivation.staleAfter(at, config)` in the same write, and
|
|
2265
|
+
* overwrite the actor's existing `verified` entry's `at` instead of
|
|
2266
|
+
* appending a duplicate. A concept without `stale_after` gets none added.
|
|
2267
|
+
* Default `false`: plain verify never touches `stale_after`.
|
|
2268
|
+
*/
|
|
2269
|
+
readonly refreshStaleAfter?: boolean;
|
|
2180
2270
|
}
|
|
2181
2271
|
/**
|
|
2182
2272
|
* Issue #214. Attests an explicit list of concept ids in one all-or-nothing
|
|
@@ -2223,6 +2313,19 @@ export declare const loadPickerCandidates: (options: PickerCandidatesOptions) =>
|
|
|
2223
2313
|
by: Actor;
|
|
2224
2314
|
candidates: readonly PickerCandidate[];
|
|
2225
2315
|
}, import("@okfit/core").BundleLoadError | import("@okfit/profiles").GeneratedByError, FileSystem.FileSystem | import("@effected/git").Git | Path.Path>;
|
|
2316
|
+
/**
|
|
2317
|
+
* Issue #228: as {@link loadPickerCandidates}, but the rows are the concepts
|
|
2318
|
+
* stale at `now` (any type, the actor's own attestations included), for
|
|
2319
|
+
* `okfit stale --verify` to re-attest and roll forward. Reads only.
|
|
2320
|
+
*
|
|
2321
|
+
* @public
|
|
2322
|
+
*/
|
|
2323
|
+
export declare const loadStaleCandidates: (options: PickerCandidatesOptions & {
|
|
2324
|
+
readonly now: DateTime.Utc;
|
|
2325
|
+
}) => Effect.Effect<{
|
|
2326
|
+
by: Actor;
|
|
2327
|
+
candidates: readonly PickerCandidate[];
|
|
2328
|
+
}, import("@okfit/core").BundleLoadError | import("@okfit/profiles").GeneratedByError, FileSystem.FileSystem | import("@effected/git").Git | Path.Path>;
|
|
2226
2329
|
//#endregion
|
|
2227
2330
|
//#region src/version.d.ts
|
|
2228
2331
|
/**
|
|
@@ -2239,5 +2342,5 @@ export declare const loadPickerCandidates: (options: PickerCandidatesOptions) =>
|
|
|
2239
2342
|
*/
|
|
2240
2343
|
export declare const ENGINE_VERSION: string;
|
|
2241
2344
|
//#endregion
|
|
2242
|
-
export type { AttestableSelection, BundleSessionOptions, BundleSessionServices, BundleSessionShape, ConceptFilter, ConceptLink, ConceptNeighbor, ContextResult, ContextRunOptions, DiagnosticSource, DiscoveredConfig, Distribution, DocumentInput, ExternalReferencesShape, GraphRunOptions, GraphRunResult, OverlayDocument, OverlayDocumentsShape, PickerCandidate, PickerCandidatesOptions, RenderedDiagnostic, ResolveProjectConfigInput, ResolvedProjectConfig, RevalidateError, RevalidateOptions, RevalidateResult, RevalidateTier, RunOptions, RunResult, ScaffoldFile, ScaffoldOptions, StaleRunOptions, StaleRunResult, SyncMode, SyncModeResult, SyncOptions, SyncResult, Tally, VerifyBatchOptions, VerifyBatchResult, VerifyBatchSkipReason, VerifyIdsOptions, VerifyOptions, VerifyResult, WatchedFilesOutcome };
|
|
2345
|
+
export type { AttestableSelection, BundleSessionOptions, BundleSessionServices, BundleSessionShape, ConceptFilter, ConceptLink, ConceptNeighbor, ContextResult, ContextRunOptions, DiagnosticSource, DiscoveredConfig, Distribution, DocumentInput, ExternalReferencesShape, GraphRunOptions, GraphRunResult, OverlayDocument, OverlayDocumentsShape, PendingWrite, PickerCandidate, PickerCandidatesOptions, RenderedDiagnostic, ResolveProjectConfigInput, ResolvedProjectConfig, RevalidateError, RevalidateOptions, RevalidateResult, RevalidateTier, RunOptions, RunResult, ScaffoldFile, ScaffoldOptions, StaleRunOptions, StaleRunResult, SyncMode, SyncModeResult, SyncOptions, SyncPlan, SyncResult, Tally, VerifyBatchOptions, VerifyBatchResult, VerifyBatchSkipReason, VerifyIdsOptions, VerifyOptions, VerifyResult, WatchedFilesOutcome };
|
|
2243
2346
|
//# sourceMappingURL=index.d.ts.map
|
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, SyncPublicationConflictError, SyncStagedLogError, VerifyConceptNotFoundError, VerifySelectionError, VerifyUnsupportedFrontmatterError } from "./errors.js";
|
|
2
|
+
import { ConfigMalformedError, ConfigPathNotFoundError, DocumentPathError, InitOverwriteError, QueryConceptNotFoundError, QuerySelectionError, QueryUnknownVocabularyError, SyncPlanStaleError, SyncPublicationConflictError, SyncStagedLogError, VerifyConceptNotFoundError, 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";
|
|
@@ -20,7 +20,7 @@ import { collect, sort } from "./render/sort.js";
|
|
|
20
20
|
import { JsonDiagnostic, JsonEnvelope, JsonErrorEnvelope, JsonSummary, json, jsonError } from "./render/json.js";
|
|
21
21
|
import { ConceptSummary, QueryGetEnvelope, QueryLink, QueryListEnvelope, QueryNeighbor, QueryNeighborsEnvelope, queryGetEnvelope, queryListEnvelope, queryNeighborsEnvelope, toConceptSummary } from "./render/query.js";
|
|
22
22
|
import { StaleEnvelope, StaleItem, StaleSummary, staleEnvelope } from "./render/stale.js";
|
|
23
|
-
import { SkipReason, runSync } from "./sync/run.js";
|
|
23
|
+
import { SkipReason, applySyncPlan, planSync, runSync } from "./sync/run.js";
|
|
24
24
|
import { PublicationEnvelope, SyncEnvelope, SyncModeEnvelope, syncEnvelope } from "./render/sync.js";
|
|
25
25
|
import { VerifyBatchEnvelope, VerifyEnvelope, verifyBatchEnvelope, verifyEnvelope } from "./render/verify.js";
|
|
26
26
|
import { Now, run } from "./validate/run.js";
|
|
@@ -29,7 +29,7 @@ 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 { resolveBatchTypes, selectAttestable, selectPickerCandidates } from "./verify/select.js";
|
|
33
|
-
import { loadPickerCandidates, runVerify, runVerifyBatch, runVerifyIds } from "./verify/run.js";
|
|
32
|
+
import { resolveBatchTypes, selectAttestable, selectPickerCandidates, selectStaleCandidates } from "./verify/select.js";
|
|
33
|
+
import { loadPickerCandidates, loadStaleCandidates, runVerify, runVerifyBatch, runVerifyIds } from "./verify/run.js";
|
|
34
34
|
|
|
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, SyncPublicationConflictError, SyncStagedLogError, UnsupportedFrontmatterError, VerifyBatchEnvelope, VerifyConceptNotFoundError, VerifyEnvelope, VerifySelectionError, VerifyUnsupportedFrontmatterError, buildConfigLayer, collect, conceptFor, configValue, contextEnvelope, files, forDiagnostics, graphEnvelope, json, jsonError, layerOverlayFileSystem, loadPickerCandidates, makeOverlayFileSystem, provideConfig, provideDocuments, queryGetEnvelope, queryListEnvelope, queryNeighborsEnvelope, resolveBatchTypes, resolveBundleRoot, resolveDocumentPath, resolveProjectConfig, resolveProjectRoot, run, runContext, runGraph, runStale, runSync, runVerify, runVerifyBatch, runVerifyIds, selectAttestable, selectPickerCandidates, sort, staleEnvelope, stampPublication, syncEnvelope, tally, targetPaths, toConceptSummary, verifyBatchEnvelope, verifyEnvelope, withFallbackRange };
|
|
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 };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@okfit/engine",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.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": [
|
|
@@ -42,13 +42,13 @@
|
|
|
42
42
|
"@effected/glob": "^0.10.0",
|
|
43
43
|
"@effected/jsonc": "^0.15.1",
|
|
44
44
|
"@effected/markdown": "^0.15.1",
|
|
45
|
-
"@effected/schemastore": "^0.21.
|
|
45
|
+
"@effected/schemastore": "^0.21.3",
|
|
46
46
|
"@effected/store": "^0.13.1",
|
|
47
47
|
"@effected/toml": "^0.11.1",
|
|
48
48
|
"@effected/walker": "^0.15.0",
|
|
49
49
|
"@effected/xdg": "^0.9.0",
|
|
50
50
|
"@effected/yaml": "^0.19.1",
|
|
51
|
-
"@okfit/core": "0.9.
|
|
51
|
+
"@okfit/core": "0.9.2",
|
|
52
52
|
"@okfit/profiles": "0.9.0",
|
|
53
53
|
"effect": "^4.0.2"
|
|
54
54
|
},
|
package/sync/generated.js
CHANGED
|
@@ -60,7 +60,7 @@ const encodeAt = Schema.encodeSync(Timestamp);
|
|
|
60
60
|
const syncGenerated = Effect.fn("okfit/sync/syncGenerated")(function* (bundle, options) {
|
|
61
61
|
const fs = yield* FileSystem.FileSystem;
|
|
62
62
|
const path = yield* Path.Path;
|
|
63
|
-
const { provenance, dryRun, agent, scope } = options;
|
|
63
|
+
const { provenance, dryRun, agent, scope, pending } = options;
|
|
64
64
|
const written = [];
|
|
65
65
|
const unchanged = [];
|
|
66
66
|
const skipped = [];
|
|
@@ -123,6 +123,10 @@ const syncGenerated = Effect.fn("okfit/sync/syncGenerated")(function* (bundle, o
|
|
|
123
123
|
}
|
|
124
124
|
const finalText = bom + MarkdownEdit.applyAll(text, edits);
|
|
125
125
|
if (dryRun) {
|
|
126
|
+
pending?.push({
|
|
127
|
+
target: absolutePath,
|
|
128
|
+
contents: finalText
|
|
129
|
+
});
|
|
126
130
|
written.push(id);
|
|
127
131
|
continue;
|
|
128
132
|
}
|
package/sync/index.js
CHANGED
|
@@ -23,12 +23,16 @@ const childDirectoriesOf = (bundle, dir) => {
|
|
|
23
23
|
}
|
|
24
24
|
return [...children];
|
|
25
25
|
};
|
|
26
|
-
const writeOrCompare = Effect.fn("okfit/sync/index/writeOrCompare")(function* (targetPath, relativeId, rendered, dryRun, written, unchanged) {
|
|
26
|
+
const writeOrCompare = Effect.fn("okfit/sync/index/writeOrCompare")(function* (targetPath, relativeId, rendered, dryRun, written, unchanged, pending) {
|
|
27
27
|
if ((yield* (yield* FileSystem.FileSystem).readFileString(targetPath).pipe(Effect.map((text) => text), Effect.catchReason("PlatformError", "NotFound", () => Effect.succeed(void 0)))) === rendered) {
|
|
28
28
|
unchanged.push(relativeId);
|
|
29
29
|
return;
|
|
30
30
|
}
|
|
31
31
|
if (dryRun) {
|
|
32
|
+
pending?.push({
|
|
33
|
+
target: targetPath,
|
|
34
|
+
contents: rendered
|
|
35
|
+
});
|
|
32
36
|
written.push(relativeId);
|
|
33
37
|
return;
|
|
34
38
|
}
|
|
@@ -46,7 +50,7 @@ const writeOrCompare = Effect.fn("okfit/sync/index/writeOrCompare")(function* (t
|
|
|
46
50
|
*
|
|
47
51
|
* @internal
|
|
48
52
|
*/
|
|
49
|
-
const syncIndex = Effect.fn("okfit/sync/syncIndex")(function* (bundle, dryRun) {
|
|
53
|
+
const syncIndex = Effect.fn("okfit/sync/syncIndex")(function* (bundle, dryRun, pending) {
|
|
50
54
|
const path = yield* Path.Path;
|
|
51
55
|
const written = [];
|
|
52
56
|
const unchanged = [];
|
|
@@ -55,11 +59,11 @@ const syncIndex = Effect.fn("okfit/sync/syncIndex")(function* (bundle, dryRun) {
|
|
|
55
59
|
okfVersion: OKF_SPEC_VERSION,
|
|
56
60
|
subdirectories: childDirectoriesOf(bundle, "")
|
|
57
61
|
});
|
|
58
|
-
yield* writeOrCompare(path.join(bundle.root, "index.md"), "index.md", rootRendered, dryRun, written, unchanged);
|
|
62
|
+
yield* writeOrCompare(path.join(bundle.root, "index.md"), "index.md", rootRendered, dryRun, written, unchanged, pending);
|
|
59
63
|
for (const dir of bundle.directories) {
|
|
60
64
|
if (dir === "") continue;
|
|
61
65
|
const rendered = Derive.synthesizeIndex(bundle, dir);
|
|
62
|
-
yield* writeOrCompare(path.join(bundle.root, dir, "index.md"), `${dir}/index.md`, rendered, dryRun, written, unchanged);
|
|
66
|
+
yield* writeOrCompare(path.join(bundle.root, dir, "index.md"), `${dir}/index.md`, rendered, dryRun, written, unchanged, pending);
|
|
63
67
|
}
|
|
64
68
|
return {
|
|
65
69
|
selected: true,
|
package/sync/log.js
CHANGED
|
@@ -91,7 +91,7 @@ const wantsLogEntry = (window, date, title) => {
|
|
|
91
91
|
*
|
|
92
92
|
* @internal
|
|
93
93
|
*/
|
|
94
|
-
const syncLog = Effect.fn("okfit/sync/syncLog")(function* (bundle, provenance, dryRun, since) {
|
|
94
|
+
const syncLog = Effect.fn("okfit/sync/syncLog")(function* (bundle, provenance, dryRun, since, pending) {
|
|
95
95
|
const fs = yield* FileSystem.FileSystem;
|
|
96
96
|
const logPath = (yield* Path.Path).join(bundle.root, "log.md");
|
|
97
97
|
const source = yield* fs.readFileString(logPath).pipe(Effect.map((text) => text), Effect.catchReason("PlatformError", "NotFound", () => Effect.succeed(void 0)));
|
|
@@ -129,12 +129,18 @@ const syncLog = Effect.fn("okfit/sync/syncLog")(function* (bundle, provenance, d
|
|
|
129
129
|
unchanged: ["log.md"],
|
|
130
130
|
skipped: []
|
|
131
131
|
};
|
|
132
|
-
if (dryRun)
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
132
|
+
if (dryRun) {
|
|
133
|
+
pending?.push({
|
|
134
|
+
target: logPath,
|
|
135
|
+
contents: merged
|
|
136
|
+
});
|
|
137
|
+
return {
|
|
138
|
+
selected: true,
|
|
139
|
+
written: ["log.md"],
|
|
140
|
+
unchanged: [],
|
|
141
|
+
skipped: []
|
|
142
|
+
};
|
|
143
|
+
}
|
|
138
144
|
yield* writeAtomic(logPath, merged);
|
|
139
145
|
return {
|
|
140
146
|
selected: true,
|
package/sync/run.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { SyncStagedLogError } from "../errors.js";
|
|
1
|
+
import { SyncPlanStaleError, SyncStagedLogError } from "../errors.js";
|
|
2
|
+
import { writeAtomic } from "./write.js";
|
|
2
3
|
import { syncGenerated } from "./generated.js";
|
|
3
4
|
import { syncIndex } from "./index.js";
|
|
4
5
|
import { logWindow, syncLog, wantsLogEntry } from "./log.js";
|
|
@@ -31,17 +32,20 @@ const UNSELECTED = {
|
|
|
31
32
|
skipped: []
|
|
32
33
|
};
|
|
33
34
|
/**
|
|
34
|
-
* Contract §5's six-step algorithm
|
|
35
|
-
* `Derivation.generatedAt` walk shared by the
|
|
36
|
-
* (issue #21)
|
|
37
|
-
* every concept
|
|
38
|
-
* index, log
|
|
39
|
-
*
|
|
40
|
-
*
|
|
35
|
+
* Contract §5's six-step algorithm, computed without writing: one
|
|
36
|
+
* `Bundle.load`, then a lazy `Derivation.generatedAt` walk shared by the
|
|
37
|
+
* generated and log modes (issue #21) -- computed only for a concept that
|
|
38
|
+
* still needs one, not for every concept -- then the three modes in a FIXED
|
|
39
|
+
* order -- generated, index, log -- regardless of `--only`'s own occurrence
|
|
40
|
+
* order. Every mode runs as a dry run and records its writes in
|
|
41
|
+
* {@link SyncPlan.pending}; no mode reads a file another mode writes (generated
|
|
42
|
+
* reads concept files, index reads `index.md`s, log reads `log.md`), which is
|
|
43
|
+
* what makes the dry-run report exact and the deferred apply safe (design §2).
|
|
44
|
+
* `options.dryRun` is ignored here: a plan never writes.
|
|
41
45
|
*
|
|
42
46
|
* @public
|
|
43
47
|
*/
|
|
44
|
-
const
|
|
48
|
+
const planSync = Effect.fn("okfit/sync/planSync")(function* (options) {
|
|
45
49
|
const bundle = yield* Bundle.load({ root: options.bundleRoot });
|
|
46
50
|
if (options.staged !== void 0 && options.modes.has("log")) return yield* new SyncStagedLogError({});
|
|
47
51
|
const walked = /* @__PURE__ */ new Map();
|
|
@@ -83,31 +87,88 @@ const runSync = Effect.fn("okfit/sync/runSync")(function* (options) {
|
|
|
83
87
|
walked.set(id, derived);
|
|
84
88
|
}
|
|
85
89
|
}
|
|
90
|
+
const pending = [];
|
|
86
91
|
const generated = options.modes.has("generated") ? {
|
|
87
92
|
selected: true,
|
|
88
93
|
...yield* syncGenerated(bundle, {
|
|
89
94
|
provenance: staged ?? walked,
|
|
90
|
-
dryRun:
|
|
95
|
+
dryRun: true,
|
|
96
|
+
pending,
|
|
91
97
|
...options.config.actors?.agent === void 0 ? {} : { agent: options.config.actors.agent },
|
|
92
98
|
...scope === void 0 ? {} : { scope }
|
|
93
99
|
})
|
|
94
100
|
} : UNSELECTED;
|
|
95
|
-
const index = options.modes.has("index") ? yield* syncIndex(bundle,
|
|
96
|
-
const log = options.modes.has("log") ? yield* syncLog(bundle, walked,
|
|
97
|
-
|
|
101
|
+
const index = options.modes.has("index") ? yield* syncIndex(bundle, true, pending) : UNSELECTED;
|
|
102
|
+
const log = options.modes.has("log") ? yield* syncLog(bundle, walked, true, options.logSince, pending) : UNSELECTED;
|
|
103
|
+
let restage;
|
|
104
|
+
if (options.staged !== void 0 && repoRoot !== void 0) {
|
|
98
105
|
const path = yield* Path.Path;
|
|
99
106
|
const writtenIds = new Set(generated.written);
|
|
100
107
|
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))];
|
|
101
|
-
if (files.length > 0)
|
|
108
|
+
if (files.length > 0) restage = {
|
|
109
|
+
repoRoot,
|
|
110
|
+
files
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
const fsForSnapshot = yield* FileSystem.FileSystem;
|
|
114
|
+
const snapshotted = [];
|
|
115
|
+
for (const write of pending) {
|
|
116
|
+
const before = yield* fsForSnapshot.readFileString(write.target).pipe(Effect.catchReason("PlatformError", "NotFound", () => Effect.succeed(null)));
|
|
117
|
+
snapshotted.push({
|
|
118
|
+
...write,
|
|
119
|
+
before
|
|
120
|
+
});
|
|
102
121
|
}
|
|
103
122
|
return {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
123
|
+
result: {
|
|
124
|
+
bundleRoot: options.bundleRoot,
|
|
125
|
+
dryRun: true,
|
|
126
|
+
generated,
|
|
127
|
+
index,
|
|
128
|
+
log
|
|
129
|
+
},
|
|
130
|
+
pending: snapshotted,
|
|
131
|
+
...restage === void 0 ? {} : { restage }
|
|
132
|
+
};
|
|
133
|
+
});
|
|
134
|
+
/**
|
|
135
|
+
* Performs exactly the writes a {@link SyncPlan} recorded (atomically, in plan
|
|
136
|
+
* order), then the `--staged` re-add, and returns the non-dry-run
|
|
137
|
+
* {@link SyncResult}. The bundle is not reloaded: the plan is applied as
|
|
138
|
+
* computed. Before writing anything it re-reads every target and fails
|
|
139
|
+
* {@link SyncPlanStaleError} (writing nothing) if one differs from what
|
|
140
|
+
* {@link planSync} saw, so the run writes exactly the plan it showed.
|
|
141
|
+
*
|
|
142
|
+
* @public
|
|
143
|
+
*/
|
|
144
|
+
const applySyncPlan = Effect.fn("okfit/sync/applySyncPlan")(function* (plan) {
|
|
145
|
+
const fs = yield* FileSystem.FileSystem;
|
|
146
|
+
const changed = [];
|
|
147
|
+
for (const write of plan.pending) {
|
|
148
|
+
if (write.before === void 0) continue;
|
|
149
|
+
if ((yield* fs.readFileString(write.target).pipe(Effect.catchReason("PlatformError", "NotFound", () => Effect.succeed(null)))) !== write.before) changed.push(write.target);
|
|
150
|
+
}
|
|
151
|
+
if (changed.length > 0) return yield* new SyncPlanStaleError({ paths: changed });
|
|
152
|
+
for (const write of plan.pending) yield* writeAtomic(write.target, write.contents);
|
|
153
|
+
if (plan.restage !== void 0) yield* (yield* Git).add(plan.restage.repoRoot, [...plan.restage.files]);
|
|
154
|
+
return {
|
|
155
|
+
...plan.result,
|
|
156
|
+
dryRun: false
|
|
157
|
+
};
|
|
158
|
+
});
|
|
159
|
+
/**
|
|
160
|
+
* `planSync`, then `applySyncPlan` unless `dryRun`.
|
|
161
|
+
*
|
|
162
|
+
* @public
|
|
163
|
+
*/
|
|
164
|
+
const runSync = Effect.fn("okfit/sync/runSync")(function* (options) {
|
|
165
|
+
const plan = yield* planSync(options);
|
|
166
|
+
if (options.dryRun) return {
|
|
167
|
+
...plan.result,
|
|
168
|
+
dryRun: true
|
|
109
169
|
};
|
|
170
|
+
return yield* applySyncPlan(plan);
|
|
110
171
|
});
|
|
111
172
|
|
|
112
173
|
//#endregion
|
|
113
|
-
export { SkipReason, runSync };
|
|
174
|
+
export { SkipReason, applySyncPlan, planSync, runSync };
|
package/verify/locate.js
CHANGED
|
@@ -362,6 +362,24 @@ const locateGeneratedBlock = Effect.fn("okfit/verify/locateGeneratedBlock")(func
|
|
|
362
362
|
insertAt: valueStart + value.length
|
|
363
363
|
};
|
|
364
364
|
});
|
|
365
|
+
/** @internal */
|
|
366
|
+
const locateVerifiedAt = Effect.fn("okfit/verify/locateVerifiedAt")(function* (source, actor) {
|
|
367
|
+
const none = { _tag: "none" };
|
|
368
|
+
const parsed = yield* parseTopLevelMapping(source);
|
|
369
|
+
if ("_tag" in parsed) return none;
|
|
370
|
+
const { valueStart, contents } = parsed;
|
|
371
|
+
const seq = contents.items.find((item) => item.key instanceof YamlScalar && item.key.value === "verified")?.value;
|
|
372
|
+
if (!(seq instanceof YamlSeq)) return none;
|
|
373
|
+
const entries = seq.items.filter((item) => item instanceof YamlMap && item.items.some((entry) => entry.key instanceof YamlScalar && entry.key.value === "by" && entry.value instanceof YamlScalar && entry.value.value === actor));
|
|
374
|
+
const at = entries[entries.length - 1]?.items.find((item) => item.key instanceof YamlScalar && item.key.value === "at")?.value;
|
|
375
|
+
if (!(at instanceof YamlScalar) || at.style === "block-literal" || at.style === "block-folded") return none;
|
|
376
|
+
return {
|
|
377
|
+
_tag: "replaceScalar",
|
|
378
|
+
start: valueStart + at.offset,
|
|
379
|
+
end: valueStart + at.offset + at.length,
|
|
380
|
+
quote: at.style
|
|
381
|
+
};
|
|
382
|
+
});
|
|
365
383
|
|
|
366
384
|
//#endregion
|
|
367
|
-
export { detectNewline, documentNewline, indentAt, locate, locateGenerated, locateGeneratedBlock, locateGeneratedBodySha256, locateTopLevelScalar, stripBom };
|
|
385
|
+
export { detectNewline, documentNewline, indentAt, locate, locateGenerated, locateGeneratedBlock, locateGeneratedBodySha256, locateTopLevelScalar, locateVerifiedAt, stripBom };
|
package/verify/run.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { VerifyConceptNotFoundError, VerifyUnsupportedFrontmatterError } from "../errors.js";
|
|
2
|
-
import { documentNewline, locate, locateTopLevelScalar, stripBom } from "./locate.js";
|
|
3
|
-
import { orderVerifyEdits, splice, spliceTopLevelScalar } from "./splice.js";
|
|
4
|
-
import { resolveBatchTypes, selectAttestable, selectPickerCandidates } from "./select.js";
|
|
5
|
-
import { Bundle, ConceptId, Timestamp } from "@okfit/core";
|
|
6
|
-
import { Effect, FileSystem, Option, Path, Schema } from "effect";
|
|
2
|
+
import { documentNewline, locate, locateTopLevelScalar, locateVerifiedAt, stripBom } from "./locate.js";
|
|
3
|
+
import { orderVerifyEdits, quoteLike, splice, spliceTopLevelScalar } from "./splice.js";
|
|
4
|
+
import { resolveBatchTypes, selectAttestable, selectPickerCandidates, selectStaleCandidates } from "./select.js";
|
|
5
|
+
import { Bundle, ConceptId, Derive, Timestamp } from "@okfit/core";
|
|
6
|
+
import { DateTime, Effect, FileSystem, Option, Path, Schema } from "effect";
|
|
7
7
|
import { Derivation } from "@okfit/profiles";
|
|
8
8
|
import { MarkdownEdit } from "@effected/markdown";
|
|
9
9
|
|
|
@@ -25,7 +25,7 @@ const UNDECODABLE_CODES = /* @__PURE__ */ new Set([
|
|
|
25
25
|
"type-missing"
|
|
26
26
|
]);
|
|
27
27
|
/** Steps 9-14 of runVerify: read, locate (fail closed), splice; no write. */
|
|
28
|
-
const prepareVerify = Effect.fn("okfit/verify/prepareVerify")(function* (bundle, concept, actor, at, status) {
|
|
28
|
+
const prepareVerify = Effect.fn("okfit/verify/prepareVerify")(function* (bundle, concept, actor, at, status, staleAfter = void 0) {
|
|
29
29
|
const fs = yield* FileSystem.FileSystem;
|
|
30
30
|
const absolutePath = (yield* Path.Path).join(bundle.root, concept.path);
|
|
31
31
|
const source = new TextDecoder("utf-8", { ignoreBOM: true }).decode(yield* fs.readFile(absolutePath));
|
|
@@ -38,10 +38,22 @@ const prepareVerify = Effect.fn("okfit/verify/prepareVerify")(function* (bundle,
|
|
|
38
38
|
});
|
|
39
39
|
const priorAt = (concept.frontmatter.verified ?? []).filter((entry) => entry.by === actor).map((entry) => Schema.encodeSync(Timestamp)(entry.at));
|
|
40
40
|
const newline = documentNewline(text);
|
|
41
|
-
|
|
41
|
+
let verifiedEdit = splice(located, {
|
|
42
42
|
by: actor,
|
|
43
43
|
at
|
|
44
44
|
}, newline);
|
|
45
|
+
let verifiedPreview = verifiedEdit.content;
|
|
46
|
+
if (staleAfter !== void 0 && priorAt.length > 0) {
|
|
47
|
+
const existing = yield* locateVerifiedAt(text, actor);
|
|
48
|
+
if (existing._tag === "replaceScalar") {
|
|
49
|
+
verifiedEdit = MarkdownEdit.make({
|
|
50
|
+
offset: existing.start,
|
|
51
|
+
length: existing.end - existing.start,
|
|
52
|
+
content: quoteLike(existing.quote, at)
|
|
53
|
+
});
|
|
54
|
+
verifiedPreview = `- by: ${actor}${newline} at: ${at}`;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
45
57
|
let statusEdit;
|
|
46
58
|
if (status !== void 0 && concept.frontmatter.status !== status) {
|
|
47
59
|
const target = yield* locateTopLevelScalar(text, "status");
|
|
@@ -52,11 +64,22 @@ const prepareVerify = Effect.fn("okfit/verify/prepareVerify")(function* (bundle,
|
|
|
52
64
|
});
|
|
53
65
|
statusEdit = spliceTopLevelScalar(target, "status", status, newline);
|
|
54
66
|
}
|
|
55
|
-
|
|
67
|
+
let staleEdit;
|
|
68
|
+
if (staleAfter !== void 0 && concept.frontmatter.stale_after !== void 0) {
|
|
69
|
+
const target = yield* locateTopLevelScalar(text, "stale_after");
|
|
70
|
+
if (target._tag === "unsupported") return yield* new VerifyUnsupportedFrontmatterError({
|
|
71
|
+
id: concept.id,
|
|
72
|
+
shape: target.shape,
|
|
73
|
+
key: "stale_after"
|
|
74
|
+
});
|
|
75
|
+
staleEdit = spliceTopLevelScalar(target, "stale_after", staleAfter, newline);
|
|
76
|
+
}
|
|
77
|
+
const ordered = orderVerifyEdits(verifiedEdit, statusEdit);
|
|
78
|
+
const edits = staleEdit === void 0 ? ordered : [...ordered, staleEdit].toSorted((a, b) => a.offset - b.offset);
|
|
56
79
|
return {
|
|
57
80
|
absolutePath,
|
|
58
81
|
finalText: bom + MarkdownEdit.applyAll(text, edits),
|
|
59
|
-
fragment:
|
|
82
|
+
fragment: staleEdit === void 0 || staleAfter === void 0 ? verifiedPreview : `${verifiedPreview.replace(/(?:\r\n|\n)$/, "")}${newline}stale_after: ${staleAfter}`,
|
|
60
83
|
statusFragment: statusEdit?.content ?? null,
|
|
61
84
|
priorAt
|
|
62
85
|
};
|
|
@@ -201,6 +224,7 @@ const runVerifyIds = Effect.fn("okfit/verify/runVerifyIds")(function* (options)
|
|
|
201
224
|
config: options.config
|
|
202
225
|
});
|
|
203
226
|
const at = Schema.encodeSync(Timestamp)(options.at);
|
|
227
|
+
const staleAfter = options.refreshStaleAfter === true ? Schema.encodeSync(Timestamp)(DateTime.makeUnsafe(Math.floor(DateTime.toEpochMillis(Derivation.staleAfter(options.at, options.config)) / 1e3) * 1e3)) : void 0;
|
|
204
228
|
const concepts = /* @__PURE__ */ new Map();
|
|
205
229
|
for (const rawId of options.ids) {
|
|
206
230
|
const { id, concept } = yield* resolveConcept(bundle, rawId);
|
|
@@ -212,7 +236,7 @@ const runVerifyIds = Effect.fn("okfit/verify/runVerifyIds")(function* (options)
|
|
|
212
236
|
prepared.push({
|
|
213
237
|
id,
|
|
214
238
|
conceptPath: concept.path,
|
|
215
|
-
...yield* prepareVerify(bundle, concept, actor, at, status)
|
|
239
|
+
...yield* prepareVerify(bundle, concept, actor, at, status, staleAfter)
|
|
216
240
|
});
|
|
217
241
|
}
|
|
218
242
|
if (!options.dryRun) for (const entry of prepared) yield* writeVerified(entry.absolutePath, entry.finalText);
|
|
@@ -248,6 +272,25 @@ const loadPickerCandidates = Effect.fn("okfit/verify/loadPickerCandidates")(func
|
|
|
248
272
|
candidates: selectPickerCandidates(bundle, options.config, by)
|
|
249
273
|
};
|
|
250
274
|
});
|
|
275
|
+
/**
|
|
276
|
+
* Issue #228: as {@link loadPickerCandidates}, but the rows are the concepts
|
|
277
|
+
* stale at `now` (any type, the actor's own attestations included), for
|
|
278
|
+
* `okfit stale --verify` to re-attest and roll forward. Reads only.
|
|
279
|
+
*
|
|
280
|
+
* @public
|
|
281
|
+
*/
|
|
282
|
+
const loadStaleCandidates = Effect.fn("okfit/verify/loadStaleCandidates")(function* (options) {
|
|
283
|
+
const bundle = yield* Bundle.load({ root: options.bundleRoot });
|
|
284
|
+
const by = yield* Derivation.generatedBy({
|
|
285
|
+
writer: "human",
|
|
286
|
+
cwd: options.projectRoot,
|
|
287
|
+
config: options.config
|
|
288
|
+
});
|
|
289
|
+
return {
|
|
290
|
+
by,
|
|
291
|
+
candidates: selectStaleCandidates(bundle, Derive.staleReport(bundle, options.now), by)
|
|
292
|
+
};
|
|
293
|
+
});
|
|
251
294
|
|
|
252
295
|
//#endregion
|
|
253
|
-
export { loadPickerCandidates, runVerify, runVerifyBatch, runVerifyIds };
|
|
296
|
+
export { loadPickerCandidates, loadStaleCandidates, runVerify, runVerifyBatch, runVerifyIds };
|
package/verify/select.js
CHANGED
|
@@ -64,6 +64,33 @@ const selectPickerCandidates = (bundle, config, actor) => {
|
|
|
64
64
|
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);
|
|
65
65
|
};
|
|
66
66
|
/**
|
|
67
|
+
* Issue #228: the picker rows for `okfit stale --verify`: one per stale item,
|
|
68
|
+
* any type, deprecated concepts excluded. Unlike {@link selectPickerCandidates}
|
|
69
|
+
* the actor's own attestation does not exclude a row, because re-attesting is
|
|
70
|
+
* the point; `otherAttestations` still counts only other actors. Sorted by
|
|
71
|
+
* type, then id.
|
|
72
|
+
*
|
|
73
|
+
* @public
|
|
74
|
+
*/
|
|
75
|
+
const selectStaleCandidates = (bundle, items, actor) => {
|
|
76
|
+
const rows = [];
|
|
77
|
+
for (const item of items) {
|
|
78
|
+
const concept = bundle.concepts.get(item.id);
|
|
79
|
+
if (concept === void 0) continue;
|
|
80
|
+
const { type, status, title, description } = concept.frontmatter;
|
|
81
|
+
if (status === "deprecated") continue;
|
|
82
|
+
rows.push({
|
|
83
|
+
id: item.id,
|
|
84
|
+
type,
|
|
85
|
+
status: status === "draft" ? "draft" : "stable",
|
|
86
|
+
title: title ?? null,
|
|
87
|
+
description: description ?? null,
|
|
88
|
+
otherAttestations: (concept.frontmatter.verified ?? []).filter((entry) => entry.by !== actor).length
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
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);
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
67
94
|
* The batch type-resolution rule shared by `runVerifyBatch` and any future
|
|
68
95
|
* interactive picker: explicit `types` must each be declared in
|
|
69
96
|
* `config.types` (else `VerifySelectionError` with reason `unknown-type`);
|
|
@@ -83,4 +110,4 @@ const resolveBatchTypes = (config, types) => {
|
|
|
83
110
|
};
|
|
84
111
|
|
|
85
112
|
//#endregion
|
|
86
|
-
export { resolveBatchTypes, selectAttestable, selectPickerCandidates };
|
|
113
|
+
export { resolveBatchTypes, selectAttestable, selectPickerCandidates, selectStaleCandidates };
|
package/verify/splice.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { MarkdownEdit } from "@effected/markdown";
|
|
2
2
|
|
|
3
3
|
//#region src/verify/splice.ts
|
|
4
|
+
/** `value` wrapped in the quote style the scalar it replaces already uses. @internal */
|
|
5
|
+
const quoteLike = (quote, value) => quote === "single-quoted" ? `'${value}'` : quote === "double-quoted" ? `"${value}"` : value;
|
|
4
6
|
/** Prefix two spaces to every line but the first, joining with `newline` (V-13). */
|
|
5
7
|
const reindent = (original, newline) => original.split(/\r\n|\n|\r/).map((line, index) => index === 0 ? line : ` ${line}`).join(newline);
|
|
6
8
|
/**
|
|
@@ -61,14 +63,11 @@ const spliceGenerated = (target, value, newline, field = "at") => {
|
|
|
61
63
|
length: 0,
|
|
62
64
|
content: `${target.indent}${field}: ${value}${newline}`
|
|
63
65
|
});
|
|
64
|
-
case "replaceScalar": {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
content: quoted
|
|
70
|
-
});
|
|
71
|
-
}
|
|
66
|
+
case "replaceScalar": return MarkdownEdit.make({
|
|
67
|
+
offset: target.start,
|
|
68
|
+
length: target.end - target.start,
|
|
69
|
+
content: quoteLike(target.quote, value)
|
|
70
|
+
});
|
|
72
71
|
}
|
|
73
72
|
};
|
|
74
73
|
/**
|
|
@@ -106,14 +105,11 @@ const spliceTopLevelScalar = (target, key, value, newline) => {
|
|
|
106
105
|
length: 0,
|
|
107
106
|
content: `${key}: ${value}${newline}`
|
|
108
107
|
});
|
|
109
|
-
case "replaceScalar": {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
content: quoted
|
|
115
|
-
});
|
|
116
|
-
}
|
|
108
|
+
case "replaceScalar": return MarkdownEdit.make({
|
|
109
|
+
offset: target.start,
|
|
110
|
+
length: target.end - target.start,
|
|
111
|
+
content: quoteLike(target.quote, value)
|
|
112
|
+
});
|
|
117
113
|
}
|
|
118
114
|
};
|
|
119
115
|
/**
|
|
@@ -165,4 +161,4 @@ const mergeSameOffset = (edits) => {
|
|
|
165
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)));
|
|
166
162
|
|
|
167
163
|
//#endregion
|
|
168
|
-
export { mergeSameOffset, orderVerifyEdits, splice, spliceGenerated, spliceGeneratedBlock, spliceGeneratedFields, spliceTopLevelScalar };
|
|
164
|
+
export { mergeSameOffset, orderVerifyEdits, quoteLike, splice, spliceGenerated, spliceGeneratedBlock, spliceGeneratedFields, spliceTopLevelScalar };
|