@opencode-ai/util 0.0.0-next-17125 → 0.0.0-next-17126
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/dist/global.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
-
import fs from "fs
|
|
2
|
+
import fs from "fs";
|
|
3
3
|
import { xdgData, xdgCache, xdgConfig, xdgState } from "xdg-basedir";
|
|
4
4
|
import os from "os";
|
|
5
5
|
import { Context, Effect, Layer } from "effect";
|
|
@@ -11,7 +11,6 @@ const cache = path.join(xdgCache, app);
|
|
|
11
11
|
const config = path.join(xdgConfig, app);
|
|
12
12
|
const state = path.join(xdgState, app);
|
|
13
13
|
const tmp = path.join(os.tmpdir(), app);
|
|
14
|
-
await fs.mkdir(tmp, { recursive: true });
|
|
15
14
|
const paths = {
|
|
16
15
|
get home() {
|
|
17
16
|
return process.env.OPENCODE_TEST_HOME ?? os.homedir();
|
|
@@ -23,35 +22,34 @@ const paths = {
|
|
|
23
22
|
cache,
|
|
24
23
|
config,
|
|
25
24
|
state,
|
|
26
|
-
tmp
|
|
25
|
+
tmp,
|
|
27
26
|
};
|
|
28
27
|
export const Path = paths;
|
|
29
28
|
Flock.setGlobal({ state });
|
|
30
|
-
await Promise.all([
|
|
31
|
-
fs.mkdir(Path.data, { recursive: true }),
|
|
32
|
-
fs.mkdir(Path.config, { recursive: true }),
|
|
33
|
-
fs.mkdir(Path.state, { recursive: true }),
|
|
34
|
-
fs.mkdir(Path.log, { recursive: true }),
|
|
35
|
-
fs.mkdir(Path.bin, { recursive: true }),
|
|
36
|
-
fs.mkdir(Path.repos, { recursive: true }),
|
|
37
|
-
]);
|
|
38
29
|
export class Service extends Context.Service()("@opencode/Global") {
|
|
39
30
|
}
|
|
40
31
|
export function make(input = {}) {
|
|
32
|
+
// The acquired service canonicalizes default tmp; use it instead of Path.tmp for path comparisons.
|
|
41
33
|
return {
|
|
42
34
|
home: Path.home,
|
|
43
35
|
data: Path.data,
|
|
44
36
|
cache: Path.cache,
|
|
45
37
|
config: Path.config,
|
|
46
38
|
state: Path.state,
|
|
47
|
-
tmp: Path.tmp,
|
|
39
|
+
tmp: input.tmp ?? Path.tmp,
|
|
48
40
|
bin: Path.bin,
|
|
49
41
|
log: Path.log,
|
|
50
42
|
repos: Path.repos,
|
|
51
43
|
...input,
|
|
52
44
|
};
|
|
53
45
|
}
|
|
54
|
-
const
|
|
46
|
+
const acquire = (input) => Effect.gen(function* () {
|
|
47
|
+
const service = Service.of(make(input));
|
|
48
|
+
yield* Effect.promise(() => Promise.all([service.data, service.config, service.state, service.log, service.bin, service.repos, service.tmp].map((directory) => fs.promises.mkdir(directory, { recursive: true }))));
|
|
49
|
+
const canonicalTmp = yield* Effect.promise(() => fs.promises.realpath(service.tmp));
|
|
50
|
+
return Service.of({ ...service, tmp: input.tmp ?? canonicalTmp });
|
|
51
|
+
});
|
|
52
|
+
const layer = Layer.effect(Service, Effect.suspend(() => acquire({ config: process.env.OPENCODE_CONFIG_DIR ?? Path.config })));
|
|
55
53
|
export const node = makeGlobalNode({ service: Service, layer: layer, deps: [] });
|
|
56
|
-
export const layerWith = (input) => Layer.effect(Service,
|
|
54
|
+
export const layerWith = (input) => Layer.effect(Service, acquire(input));
|
|
57
55
|
export * as Global from "./global.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Logger } from "effect";
|
|
1
|
+
import { Effect, FileSystem, Logger } from "effect";
|
|
2
2
|
export declare function file(local?: boolean, channel?: string): string;
|
|
3
|
-
export declare function fileLogger(target?: string, id?: string):
|
|
3
|
+
export declare function fileLogger(target?: string, id?: string): Effect.Effect<Logger.Logger<unknown, void>, import("effect/PlatformError").PlatformError, FileSystem.FileSystem | import("effect/Scope").Scope>;
|
|
4
4
|
export declare function minimumLogLevel(): "Error" | "Warn" | "Info" | "Debug";
|
|
5
|
-
export declare function loggers(local?: boolean, channel?: string): (
|
|
5
|
+
export declare function loggers(local?: boolean, channel?: string): (Effect.Effect<Logger.Logger<unknown, void>, import("effect/PlatformError").PlatformError, FileSystem.FileSystem | import("effect/Scope").Scope> | Logger.Logger<unknown, boolean>)[];
|
|
6
6
|
export * as Logging from "./logging.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Formatter, Logger } from "effect";
|
|
1
|
+
import { Effect, FileSystem, Formatter, Logger } from "effect";
|
|
2
2
|
import path from "path";
|
|
3
3
|
import { Global } from "../global.js";
|
|
4
4
|
import { runID } from "./shared.js";
|
|
@@ -47,7 +47,11 @@ export function file(local = true, channel = "local") {
|
|
|
47
47
|
}
|
|
48
48
|
export function fileLogger(target = file(), id = runID) {
|
|
49
49
|
// Do not set batchWindow to 0; it causes high idle CPU usage.
|
|
50
|
-
return
|
|
50
|
+
return Effect.gen(function* () {
|
|
51
|
+
const fs = yield* FileSystem.FileSystem;
|
|
52
|
+
yield* fs.makeDirectory(path.dirname(target), { recursive: true });
|
|
53
|
+
return yield* Logger.toFile(formatter(id), target, { flag: "a" });
|
|
54
|
+
});
|
|
51
55
|
}
|
|
52
56
|
const stderrLogger = Logger.make((options) => process.stderr.write(formatter().log(options) + "\n"));
|
|
53
57
|
export function minimumLogLevel() {
|