Use Effect time APIs for VCS and workspace scans

- Switch freshness and scan timestamps to `DateTime.now` from Effect
- Keep timestamps consistent within each async operation
This commit is contained in:
Julius Marminge authored and Julius Marminge committed 2026-05-02 14:22:13 -07:00
1 parent 2bf08b8656
commit 2bf290532f
2 files changed
+18 -12

No files matched your search

+13 -9
View File
@@ -1,4 +1,4 @@
import { Effect, Layer } from "effect";
import { DateTime, Effect, Layer } from "effect";
import { VcsProcessExitError } from "@t3tools/contracts";
import { makeGitCore } from "../git/Layers/GitCore.ts";
@@ -14,12 +14,13 @@ const WORKSPACE_GIT_HARDENED_CONFIG_ARGS = [
"core.untrackedCache=false",
] as const;
function nowFreshness() {
const nowFreshness = Effect.fn("GitVcsDriver.nowFreshness")(function* () {
const now = yield* DateTime.now;
return {
source: "live-local" as const,
observedAt: new Date().toISOString(),
observedAt: DateTime.formatIso(now),
};
}
});
function splitNullSeparatedPaths(input: string, truncated: boolean): string[] {
const parts = input.split("\0");
@@ -147,7 +148,7 @@ export const make = Effect.fn("makeGitVcsDriver")(function* () {
kind: "git" as const,
rootPath: root.stdout.trim(),
metadataPath: gitCommonDir?.stdout.trim() || null,
freshness: nowFreshness(),
freshness: yield* nowFreshness(),
};
},
);
@@ -174,10 +175,13 @@ export const make = Effect.fn("makeGitVcsDriver")(function* () {
).pipe(
Effect.flatMap((result) =>
result.exitCode === 0
? Effect.succeed({
paths: splitNullSeparatedPaths(result.stdout, result.stdoutTruncated),
truncated: result.stdoutTruncated,
freshness: nowFreshness(),
? Effect.gen(function* () {
const freshness = yield* nowFreshness();
return {
paths: splitNullSeparatedPaths(result.stdout, result.stdoutTruncated),
truncated: result.stdoutTruncated,
freshness,
};
})
: Effect.fail(
new VcsProcessExitError({
@@ -2,7 +2,7 @@ import * as OS from "node:os";
import fsPromises from "node:fs/promises";
import type { Dirent } from "node:fs";
import { Cache, Duration, Effect, Exit, Layer, Option, Path } from "effect";
import { Cache, DateTime, Duration, Effect, Exit, Layer, Option, Path } from "effect";
import { type FilesystemBrowseInput, type ProjectEntry } from "@t3tools/contracts";
import { isExplicitRelativePath, isWindowsAbsolutePath } from "@t3tools/shared/path";
@@ -248,9 +248,10 @@ export const makeWorkspaceEntries = Effect.gen(function* () {
)
.map(toSearchableWorkspaceEntry);
const now = yield* DateTime.now;
const entries = [...directoryEntries, ...fileEntries];
return {
scannedAt: Date.now(),
scannedAt: now.epochMilliseconds,
entries: entries.slice(0, WORKSPACE_INDEX_MAX_ENTRIES),
truncated: listedFiles.truncated || entries.length > WORKSPACE_INDEX_MAX_ENTRIES,
};
@@ -368,8 +369,9 @@ export const makeWorkspaceEntries = Effect.gen(function* () {
}
}
const now = yield* DateTime.now;
return {
scannedAt: Date.now(),
scannedAt: now.epochMilliseconds,
entries,
truncated,
};