@okfit/engine 0.19.1 → 0.20.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/package.json +17 -16
- package/sync/write.js +9 -37
- package/targets/resolve.js +2 -23
- package/verify/run.js +2 -7
- package/version.js +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@okfit/engine",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.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": [
|
|
@@ -35,22 +35,23 @@
|
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@effect/platform-node": "~4.1.2",
|
|
38
|
-
"@effected/app": "^0.31.
|
|
39
|
-
"@effected/config-file": "^0.
|
|
38
|
+
"@effected/app": "^0.31.1",
|
|
39
|
+
"@effected/config-file": "^0.25.0",
|
|
40
|
+
"@effected/files": "^0.1.0",
|
|
40
41
|
"@effected/git": "^0.30.0",
|
|
41
|
-
"@effected/glob": "^0.
|
|
42
|
-
"@effected/jsonc": "^0.
|
|
43
|
-
"@effected/kit": "^0.
|
|
44
|
-
"@effected/markdown": "^0.
|
|
45
|
-
"@effected/schemastore": "^0.
|
|
46
|
-
"@effected/source": "^0.
|
|
47
|
-
"@effected/store": "^0.
|
|
48
|
-
"@effected/toml": "^0.19.
|
|
49
|
-
"@effected/walker": "^0.25.
|
|
50
|
-
"@effected/xdg": "^0.19.
|
|
51
|
-
"@effected/yaml": "^0.
|
|
52
|
-
"@okfit/core": "0.
|
|
53
|
-
"@okfit/profiles": "0.14.
|
|
42
|
+
"@effected/glob": "^0.19.0",
|
|
43
|
+
"@effected/jsonc": "^0.24.0",
|
|
44
|
+
"@effected/kit": "^0.13.0",
|
|
45
|
+
"@effected/markdown": "^0.27.0",
|
|
46
|
+
"@effected/schemastore": "^0.30.0",
|
|
47
|
+
"@effected/source": "^0.4.0",
|
|
48
|
+
"@effected/store": "^0.24.0",
|
|
49
|
+
"@effected/toml": "^0.19.1",
|
|
50
|
+
"@effected/walker": "^0.25.1",
|
|
51
|
+
"@effected/xdg": "^0.19.1",
|
|
52
|
+
"@effected/yaml": "^0.29.0",
|
|
53
|
+
"@okfit/core": "0.13.0",
|
|
54
|
+
"@okfit/profiles": "0.14.2",
|
|
54
55
|
"effect": "~4.1.2"
|
|
55
56
|
},
|
|
56
57
|
"engines": {
|
package/sync/write.js
CHANGED
|
@@ -1,47 +1,19 @@
|
|
|
1
|
-
import { Effect
|
|
2
|
-
import {
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { AtomicFile } from "@effected/files";
|
|
3
3
|
|
|
4
4
|
// src/sync/write.ts
|
|
5
5
|
/**
|
|
6
|
-
* S-33: the one atomic write every sync mode shares
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* both write files that may not exist yet; `generated` mode's targets
|
|
13
|
-
* always exist, since they come from an already-loaded concept). Writes
|
|
14
|
-
* `contents` to a uniquely-scoped temp file beside the resolved target (so
|
|
15
|
-
* two concurrent `sync` runs never collide on a fixed name), preserves an
|
|
16
|
-
* existing target's mode via `stat` + `chmod` (a brand-new file keeps
|
|
17
|
-
* whatever mode `writeFileString` gives it), and renames the temp file
|
|
18
|
-
* over the target. On any failure -- including a failed `rename` -- the
|
|
19
|
-
* temp file is removed (`Effect.onError`), so a partial write never
|
|
20
|
-
* leaves a stray `<file>.okfit-sync.<token>.tmp` behind (F-5/S-33).
|
|
21
|
-
*
|
|
22
|
-
* DISCREPANCY from S-33's literal "the temp name carries the pid": `src/`
|
|
23
|
-
* outside `bin.ts`/`commands/*`/`internal/exit.ts`/`internal/tty.ts` never
|
|
24
|
-
* reads the global `process` (K-39, enforced by `__test__/boundaries.test.ts`),
|
|
25
|
-
* and `sync/write.ts` is not on that allowlist. A random UUIDv4 token
|
|
26
|
-
* (`SecureRandom.uuidV4Unsafe` from `effect/crypto`, not `process`) satisfies S-33's actual requirement --
|
|
27
|
-
* two concurrent `sync` runs never collide on a fixed temp name -- without
|
|
28
|
-
* widening the process-access boundary for one helper. Recorded here per
|
|
29
|
-
* the Global Constraints' "record the discrepancy" instruction.
|
|
6
|
+
* S-33: the one atomic write every sync mode shares, over the kit's
|
|
7
|
+
* `AtomicFile.write`. A symlinked `index.md`/`log.md`/concept file is written
|
|
8
|
+
* through its link, an existing file keeps its mode, a file `sync` creates for
|
|
9
|
+
* the first time is simply created, and a failure at any step leaves the
|
|
10
|
+
* target untouched with no temp file behind. A target without write permission
|
|
11
|
+
* is refused rather than replaced.
|
|
30
12
|
*
|
|
31
13
|
* @internal
|
|
32
14
|
*/
|
|
33
15
|
const writeAtomic = Effect.fn("okfit/sync/writeAtomic")(function* (target, contents) {
|
|
34
|
-
|
|
35
|
-
const path = yield* Path.Path;
|
|
36
|
-
const resolved = yield* fs.realPath(target).pipe(Effect.catchReason("PlatformError", "NotFound", () => Effect.succeed(target)));
|
|
37
|
-
const dir = path.dirname(resolved);
|
|
38
|
-
const base = path.basename(resolved);
|
|
39
|
-
const tempPath = path.join(dir, `${base}.okfit-sync.${SecureRandom.uuidV4Unsafe()}.tmp`);
|
|
40
|
-
const originalMode = yield* fs.stat(resolved).pipe(Effect.map((info) => Option.some(info.mode)), Effect.catchReason("PlatformError", "NotFound", () => Effect.succeed(Option.none())));
|
|
41
|
-
yield* fs.writeFileString(tempPath, contents).pipe(Effect.tap(() => Option.match(originalMode, {
|
|
42
|
-
onNone: () => Effect.void,
|
|
43
|
-
onSome: (mode) => fs.chmod(tempPath, mode)
|
|
44
|
-
})), Effect.tap(() => fs.rename(tempPath, resolved)), Effect.onError(() => fs.remove(tempPath, { force: true }).pipe(Effect.ignore)));
|
|
16
|
+
yield* AtomicFile.write(target, contents);
|
|
45
17
|
});
|
|
46
18
|
|
|
47
19
|
export { writeAtomic };
|
package/targets/resolve.js
CHANGED
|
@@ -3,21 +3,9 @@ import { relativeInside } from "./inside.js";
|
|
|
3
3
|
import { ConceptId } from "@okfit/core";
|
|
4
4
|
import { Effect, FileSystem, Option, Path } from "effect";
|
|
5
5
|
import { posix } from "node:path";
|
|
6
|
+
import { EditDistance } from "@effected/source";
|
|
6
7
|
|
|
7
8
|
// src/targets/resolve.ts
|
|
8
|
-
const levenshtein = (a, b) => {
|
|
9
|
-
const row = Array.from({ length: b.length + 1 }, (_, i) => i);
|
|
10
|
-
for (let i = 1; i <= a.length; i++) {
|
|
11
|
-
let previous = row[0] ?? 0;
|
|
12
|
-
row[0] = i;
|
|
13
|
-
for (let j = 1; j <= b.length; j++) {
|
|
14
|
-
const current = row[j] ?? 0;
|
|
15
|
-
row[j] = Math.min(current + 1, (row[j - 1] ?? 0) + 1, previous + (a[i - 1] === b[j - 1] ? 0 : 1));
|
|
16
|
-
previous = current;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return row[b.length] ?? 0;
|
|
20
|
-
};
|
|
21
9
|
const suggest = (arg, bundle) => {
|
|
22
10
|
const wanted = Option.getOrUndefined(ConceptId.normalize(arg));
|
|
23
11
|
if (wanted === void 0) return void 0;
|
|
@@ -25,16 +13,7 @@ const suggest = (arg, bundle) => {
|
|
|
25
13
|
const base = posix.basename(wanted);
|
|
26
14
|
const byBase = ids.filter((id) => posix.basename(id) === base);
|
|
27
15
|
if (byBase.length === 1) return byBase[0];
|
|
28
|
-
|
|
29
|
-
let best;
|
|
30
|
-
for (const id of ids) {
|
|
31
|
-
const distance = levenshtein(wanted, id);
|
|
32
|
-
if (distance <= limit && (best === void 0 || distance < best.distance)) best = {
|
|
33
|
-
id,
|
|
34
|
-
distance
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
return best?.id;
|
|
16
|
+
return EditDistance.suggest(wanted, ids, { maxDistance: Math.max(2, Math.floor(wanted.length / 3)) })[0];
|
|
38
17
|
};
|
|
39
18
|
const withSuggestion = (arg, bundle) => {
|
|
40
19
|
const suggestion = suggest(arg, bundle);
|
package/verify/run.js
CHANGED
|
@@ -9,6 +9,7 @@ import { Bundle, ConceptId, Derive, Timestamp } from "@okfit/core";
|
|
|
9
9
|
import { DateTime, Effect, FileSystem, Option, Path, Schema } from "effect";
|
|
10
10
|
import { Derivation, Trust } from "@okfit/profiles";
|
|
11
11
|
import { MarkdownEdit } from "@effected/markdown";
|
|
12
|
+
import { AtomicFile } from "@effected/files";
|
|
12
13
|
|
|
13
14
|
// src/verify/run.ts
|
|
14
15
|
/**
|
|
@@ -106,13 +107,7 @@ const prepareVerify = Effect.fn("okfit/verify/prepareVerify")(function* (bundle,
|
|
|
106
107
|
});
|
|
107
108
|
/** The I4/V-16 atomic write: real path, temp beside it, mode preserved, rename. */
|
|
108
109
|
const writeVerified = Effect.fn("okfit/verify/writeVerified")(function* (absolutePath, finalText) {
|
|
109
|
-
|
|
110
|
-
const target = yield* fs.realPath(absolutePath);
|
|
111
|
-
const tempPath = `${target}.okfit-verify.tmp`;
|
|
112
|
-
const original = yield* fs.stat(target);
|
|
113
|
-
yield* fs.writeFileString(tempPath, finalText);
|
|
114
|
-
yield* fs.chmod(tempPath, original.mode);
|
|
115
|
-
yield* fs.rename(tempPath, target).pipe(Effect.onError(() => fs.remove(tempPath, { force: true }).pipe(Effect.ignore)));
|
|
110
|
+
yield* AtomicFile.write(absolutePath, finalText);
|
|
116
111
|
});
|
|
117
112
|
/** Steps 7a-7d of runVerify, shared with `runVerifyIds`: tolerant id, reserved file, located concept. */
|
|
118
113
|
const resolveConcept = (bundle, rawId) => Effect.gen(function* () {
|