@radheim/util 0.0.0-stage → 2.4.3
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/abort.d.ts +1 -0
- package/dist/abort.js +8 -0
- package/dist/activity-calendar.d.ts +21 -0
- package/dist/activity-calendar.js +42 -0
- package/dist/artifact.d.ts +4 -0
- package/dist/artifact.js +85 -0
- package/dist/base64.d.ts +4 -0
- package/dist/base64.js +24 -0
- package/dist/binary.d.ts +7 -0
- package/dist/binary.js +34 -0
- package/dist/bom.d.ts +22 -0
- package/dist/bom.js +36 -0
- package/dist/cross-spawn-spawner.d.ts +9 -0
- package/dist/cross-spawn-spawner.js +548 -0
- package/dist/duration.d.ts +2 -0
- package/dist/duration.js +22 -0
- package/dist/effect/app-node-platform.d.ts +13 -0
- package/dist/effect/app-node-platform.js +29 -0
- package/dist/effect/app-node.d.ts +16 -0
- package/dist/effect/app-node.js +8 -0
- package/dist/effect/layer-node.d.ts +178 -0
- package/dist/effect/layer-node.js +248 -0
- package/dist/effect-flock.d.ts +31 -0
- package/dist/effect-flock.js +186 -0
- package/dist/encode.d.ts +4 -0
- package/dist/encode.js +38 -0
- package/dist/execute-output.d.ts +10 -0
- package/dist/execute-output.js +22 -0
- package/dist/flock.d.ts +28 -0
- package/dist/flock.js +267 -0
- package/dist/fs-util.d.ts +54 -0
- package/dist/fs-util.js +200 -0
- package/dist/glob.d.ts +18 -0
- package/dist/glob.js +29 -0
- package/dist/global-roots.d.ts +8 -0
- package/dist/global-roots.js +17 -0
- package/dist/global-roots.workerd.d.ts +7 -0
- package/dist/global-roots.workerd.js +15 -0
- package/dist/global.d.ts +30 -0
- package/dist/global.js +54 -0
- package/dist/hash.d.ts +4 -0
- package/dist/hash.js +12 -0
- package/dist/heap-snapshot.d.ts +19 -0
- package/dist/heap-snapshot.js +38 -0
- package/dist/no-timeout-fetch.d.ts +1 -0
- package/dist/no-timeout-fetch.js +4 -0
- package/dist/npm-config.d.ts +4 -0
- package/dist/npm-config.js +34 -0
- package/dist/npm.d.ts +45 -0
- package/dist/npm.js +441 -0
- package/dist/observability/logging.d.ts +14 -0
- package/dist/observability/logging.js +151 -0
- package/dist/observability/otlp.d.ts +19 -0
- package/dist/observability/otlp.js +63 -0
- package/dist/observability/shared.d.ts +1 -0
- package/dist/observability/shared.js +7 -0
- package/dist/observability/tracing.d.ts +2 -0
- package/dist/observability/tracing.js +3 -0
- package/dist/observability.d.ts +13 -0
- package/dist/observability.js +37 -0
- package/dist/open.d.ts +2 -0
- package/dist/open.js +10 -0
- package/dist/patch.d.ts +43 -0
- package/dist/patch.js +332 -0
- package/dist/path.d.ts +20 -0
- package/dist/path.js +134 -0
- package/dist/process-signal.d.ts +5 -0
- package/dist/process-signal.js +22 -0
- package/dist/process.d.ts +54 -0
- package/dist/process.js +167 -0
- package/dist/qr.d.ts +15 -0
- package/dist/qr.js +295 -0
- package/dist/record.d.ts +2 -0
- package/dist/record.js +2 -0
- package/dist/retry.d.ts +8 -0
- package/dist/retry.js +45 -0
- package/dist/runtime/import.bun.d.ts +2 -0
- package/dist/runtime/import.bun.js +8 -0
- package/dist/runtime/import.node.d.ts +2 -0
- package/dist/runtime/import.node.js +62 -0
- package/dist/runtime/import.workerd.d.ts +2 -0
- package/dist/runtime/import.workerd.js +7 -0
- package/dist/runtime-import.d.ts +1 -0
- package/dist/runtime-import.js +1 -0
- package/dist/session-mention.d.ts +11 -0
- package/dist/session-mention.js +18 -0
- package/dist/session-title-fallback.d.ts +16 -0
- package/dist/session-title-fallback.js +23 -0
- package/dist/session-turn.d.ts +37 -0
- package/dist/session-turn.js +56 -0
- package/dist/teardown.d.ts +8 -0
- package/dist/teardown.js +16 -0
- package/dist/text-boundary.d.ts +11 -0
- package/dist/text-boundary.js +22 -0
- package/dist/uuid.d.ts +1 -0
- package/dist/uuid.js +14 -0
- package/package.json +71 -4
- package/README.md +0 -3
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import os from "os";
|
|
2
|
+
import path from "path";
|
|
3
|
+
const home = os.homedir();
|
|
4
|
+
const data = process.env.XDG_DATA_HOME || (home ? path.join(home, ".local", "share") : undefined);
|
|
5
|
+
const cache = process.env.XDG_CACHE_HOME || (home ? path.join(home, ".cache") : undefined);
|
|
6
|
+
const config = process.env.XDG_CONFIG_HOME || (home ? path.join(home, ".config") : undefined);
|
|
7
|
+
const state = process.env.XDG_STATE_HOME || (home ? path.join(home, ".local", "state") : undefined);
|
|
8
|
+
/** The XDG base directories that root opencode's global paths. */
|
|
9
|
+
export function roots(app) {
|
|
10
|
+
return {
|
|
11
|
+
data: path.join(data, app),
|
|
12
|
+
cache: path.join(cache, app),
|
|
13
|
+
config: path.join(config, app),
|
|
14
|
+
state: path.join(state, app),
|
|
15
|
+
tmp: path.join(os.tmpdir(), app),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import os from "os";
|
|
2
|
+
import path from "path";
|
|
3
|
+
// workerd has no home directory or XDG base dirs and only tmp is writable, so
|
|
4
|
+
// every global path roots under one directory there. Nothing durable lives in
|
|
5
|
+
// these: on workerd the database is on Durable Object storage.
|
|
6
|
+
export function roots(app) {
|
|
7
|
+
const root = path.join(os.tmpdir(), app);
|
|
8
|
+
return {
|
|
9
|
+
data: path.join(root, "data"),
|
|
10
|
+
cache: path.join(root, "cache"),
|
|
11
|
+
config: path.join(root, "config"),
|
|
12
|
+
state: path.join(root, "state"),
|
|
13
|
+
tmp: path.join(root, "tmp"),
|
|
14
|
+
};
|
|
15
|
+
}
|
package/dist/global.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Context, Layer } from "effect";
|
|
2
|
+
export declare const Path: {
|
|
3
|
+
readonly home: string;
|
|
4
|
+
data: string;
|
|
5
|
+
bin: string;
|
|
6
|
+
log: string;
|
|
7
|
+
repos: string;
|
|
8
|
+
cache: string;
|
|
9
|
+
config: string;
|
|
10
|
+
state: string;
|
|
11
|
+
tmp: string;
|
|
12
|
+
};
|
|
13
|
+
declare const Service_base: Context.ServiceClass<Service, "@radheim/Global", Interface>;
|
|
14
|
+
export declare class Service extends Service_base {
|
|
15
|
+
}
|
|
16
|
+
export interface Interface {
|
|
17
|
+
readonly home: string;
|
|
18
|
+
readonly data: string;
|
|
19
|
+
readonly cache: string;
|
|
20
|
+
readonly config: string;
|
|
21
|
+
readonly state: string;
|
|
22
|
+
readonly tmp: string;
|
|
23
|
+
readonly bin: string;
|
|
24
|
+
readonly log: string;
|
|
25
|
+
readonly repos: string;
|
|
26
|
+
}
|
|
27
|
+
export declare function make(input?: Partial<Interface>): Interface;
|
|
28
|
+
export declare const node: import("./effect/layer-node.js").Provider<Service, never, import("./effect/layer-node.js").Tag<"global">, true>;
|
|
29
|
+
export declare const layerWith: (input: Partial<Interface>) => Layer.Layer<Service, never, never>;
|
|
30
|
+
export * as Global from "./global.js";
|
package/dist/global.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import os from "os";
|
|
4
|
+
import { Context, Effect, Layer } from "effect";
|
|
5
|
+
// XDG on runtimes with a home directory; one tmp-rooted directory on workerd.
|
|
6
|
+
// The variants resolve through the `workerd` bundle condition, like the
|
|
7
|
+
// native-module stubs, so no runtime sniffing happens here.
|
|
8
|
+
import { roots } from "#global-roots";
|
|
9
|
+
import { Flock } from "./flock.js";
|
|
10
|
+
import { makeGlobalNode } from "./effect/app-node.js";
|
|
11
|
+
const app = "opencode";
|
|
12
|
+
const { data, cache, config, state, tmp } = roots(app);
|
|
13
|
+
const paths = {
|
|
14
|
+
get home() {
|
|
15
|
+
return process.env.OPENCODE_TEST_HOME ?? os.homedir();
|
|
16
|
+
},
|
|
17
|
+
data,
|
|
18
|
+
bin: path.join(cache, "bin"),
|
|
19
|
+
log: path.join(data, "log"),
|
|
20
|
+
repos: path.join(data, "repos"),
|
|
21
|
+
cache,
|
|
22
|
+
config,
|
|
23
|
+
state,
|
|
24
|
+
tmp,
|
|
25
|
+
};
|
|
26
|
+
export const Path = paths;
|
|
27
|
+
Flock.setGlobal({ state });
|
|
28
|
+
export class Service extends Context.Service()("@radheim/Global") {
|
|
29
|
+
}
|
|
30
|
+
export function make(input = {}) {
|
|
31
|
+
// The acquired service canonicalizes default tmp; use it instead of Path.tmp for path comparisons.
|
|
32
|
+
return {
|
|
33
|
+
home: Path.home,
|
|
34
|
+
data: Path.data,
|
|
35
|
+
cache: Path.cache,
|
|
36
|
+
config: Path.config,
|
|
37
|
+
state: Path.state,
|
|
38
|
+
tmp: input.tmp ?? Path.tmp,
|
|
39
|
+
bin: Path.bin,
|
|
40
|
+
log: Path.log,
|
|
41
|
+
repos: Path.repos,
|
|
42
|
+
...input,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
const acquire = (input) => Effect.gen(function* () {
|
|
46
|
+
const service = Service.of(make(input));
|
|
47
|
+
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 }))));
|
|
48
|
+
const canonicalTmp = yield* Effect.promise(() => fs.promises.realpath(service.tmp));
|
|
49
|
+
return Service.of({ ...service, tmp: input.tmp ?? canonicalTmp });
|
|
50
|
+
});
|
|
51
|
+
const layer = Layer.effect(Service, Effect.suspend(() => acquire({ config: process.env.OPENCODE_CONFIG_DIR ?? Path.config })));
|
|
52
|
+
export const node = makeGlobalNode({ service: Service, layer: layer, deps: [] });
|
|
53
|
+
export const layerWith = (input) => Layer.effect(Service, acquire(input));
|
|
54
|
+
export * as Global from "./global.js";
|
package/dist/hash.d.ts
ADDED
package/dist/hash.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { createHash } from "crypto";
|
|
2
|
+
export var Hash;
|
|
3
|
+
(function (Hash) {
|
|
4
|
+
function fast(input) {
|
|
5
|
+
return createHash("sha1").update(input).digest("hex");
|
|
6
|
+
}
|
|
7
|
+
Hash.fast = fast;
|
|
8
|
+
function sha256(input) {
|
|
9
|
+
return createHash("sha256").update(input).digest("hex");
|
|
10
|
+
}
|
|
11
|
+
Hash.sha256 = sha256;
|
|
12
|
+
})(Hash || (Hash = {}));
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
/**
|
|
3
|
+
* Writes a V8 heap snapshot of this process into `directory` and returns once the file is complete, with the
|
|
4
|
+
* process's memory just before the snapshot: the snapshot holds only the garbage-collected heap, and writing it
|
|
5
|
+
* raises the process's memory. Blocks the event loop while the heap serializes. The file can contain secrets, so it
|
|
6
|
+
* is created owner-only before the runtime writes into it.
|
|
7
|
+
*/
|
|
8
|
+
export declare const write: (directory: string) => Effect.Effect<{
|
|
9
|
+
path: string;
|
|
10
|
+
pid: number;
|
|
11
|
+
memory: {
|
|
12
|
+
rss: number;
|
|
13
|
+
heapTotal: number;
|
|
14
|
+
heapUsed: number;
|
|
15
|
+
external: number;
|
|
16
|
+
arrayBuffers: number;
|
|
17
|
+
};
|
|
18
|
+
}, import("effect/Cause").UnknownError, never>;
|
|
19
|
+
export * as HeapSnapshot from "./heap-snapshot.js";
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Clock, Effect, Semaphore } from "effect";
|
|
2
|
+
import { mkdir, open } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
// One process-wide permit: the signal listener and the HTTP endpoint share it, so concurrent
|
|
5
|
+
// requests queue instead of serializing two heaps at once.
|
|
6
|
+
const lock = Semaphore.makeUnsafe(1);
|
|
7
|
+
/**
|
|
8
|
+
* Writes a V8 heap snapshot of this process into `directory` and returns once the file is complete, with the
|
|
9
|
+
* process's memory just before the snapshot: the snapshot holds only the garbage-collected heap, and writing it
|
|
10
|
+
* raises the process's memory. Blocks the event loop while the heap serializes. The file can contain secrets, so it
|
|
11
|
+
* is created owner-only before the runtime writes into it.
|
|
12
|
+
*/
|
|
13
|
+
export const write = Effect.fn("HeapSnapshot.write")(function* (directory) {
|
|
14
|
+
const v8 = yield* Effect.tryPromise(() => import("node:v8"));
|
|
15
|
+
const time = new Date(yield* Clock.currentTimeMillis).toISOString().replace(/[:.]/g, "");
|
|
16
|
+
const file = path.join(directory, `heap-${process.pid}-${time}.heapsnapshot`);
|
|
17
|
+
yield* Effect.tryPromise(async () => {
|
|
18
|
+
await mkdir(directory, { recursive: true });
|
|
19
|
+
const handle = await open(file, "wx", 0o600);
|
|
20
|
+
await handle.close();
|
|
21
|
+
});
|
|
22
|
+
const memory = yield* Effect.sync(() => process.memoryUsage());
|
|
23
|
+
yield* Effect.logInfo("writing heap snapshot", { path: file, rss: memory.rss, heapUsed: memory.heapUsed });
|
|
24
|
+
yield* Effect.try(() => v8.writeHeapSnapshot(file));
|
|
25
|
+
yield* Effect.logInfo("heap snapshot written", { path: file });
|
|
26
|
+
return {
|
|
27
|
+
path: file,
|
|
28
|
+
pid: process.pid,
|
|
29
|
+
memory: {
|
|
30
|
+
rss: memory.rss,
|
|
31
|
+
heapTotal: memory.heapTotal,
|
|
32
|
+
heapUsed: memory.heapUsed,
|
|
33
|
+
external: memory.external,
|
|
34
|
+
arrayBuffers: memory.arrayBuffers,
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}, (effect) => lock.withPermit(effect));
|
|
38
|
+
export * as HeapSnapshot from "./heap-snapshot.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const noTimeoutFetch: typeof fetch;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
// Bun's fetch aborts requests after its default idle deadline (about five minutes). Clients that
|
|
2
|
+
// hold requests open for long-running work (session waits, event streams, plugin commands,
|
|
3
|
+
// shell calls) opt out while keeping every other init option, including `signal`.
|
|
4
|
+
export const noTimeoutFetch = ((request, init) => fetch(request, { ...init, timeout: false }));
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export * as NpmConfig from "./npm-config.js";
|
|
2
|
+
import { fileURLToPath } from "url";
|
|
3
|
+
import { Effect } from "effect";
|
|
4
|
+
export const load = (dir) => Effect.tryPromise({
|
|
5
|
+
try: async () => {
|
|
6
|
+
// @ts-expect-error npm does not publish types for this internal config API.
|
|
7
|
+
const { default: Config } = await import("@npmcli/config");
|
|
8
|
+
// @ts-expect-error npm does not publish types for this internal config API.
|
|
9
|
+
const { default: npmDefinitions } = await import("@npmcli/config/lib/definitions/index.js");
|
|
10
|
+
const { definitions, flatten, nerfDarts, shorthands } = npmDefinitions;
|
|
11
|
+
const config = new Config({
|
|
12
|
+
// Resolved per call: on workerd import.meta.url is undefined and building
|
|
13
|
+
// this URL at module scope fails startup validation; npm config never runs there.
|
|
14
|
+
npmPath: fileURLToPath(new URL("..", import.meta.url)),
|
|
15
|
+
cwd: dir,
|
|
16
|
+
env: { ...process.env },
|
|
17
|
+
argv: [process.execPath, process.execPath, "--prefix", dir],
|
|
18
|
+
execPath: process.execPath,
|
|
19
|
+
platform: process.platform,
|
|
20
|
+
definitions,
|
|
21
|
+
flatten,
|
|
22
|
+
nerfDarts,
|
|
23
|
+
shorthands,
|
|
24
|
+
warn: false,
|
|
25
|
+
});
|
|
26
|
+
await config.load();
|
|
27
|
+
return config.flat;
|
|
28
|
+
},
|
|
29
|
+
catch: (cause) => cause,
|
|
30
|
+
}).pipe(Effect.orElseSucceed(() => ({})));
|
|
31
|
+
export const registry = (dir) => load(dir).pipe(Effect.map((config) => {
|
|
32
|
+
const registry = typeof config.registry === "string" ? config.registry : "https://registry.npmjs.org";
|
|
33
|
+
return registry.endsWith("/") ? registry.slice(0, -1) : registry;
|
|
34
|
+
}));
|
package/dist/npm.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export * as Npm from "./npm.js";
|
|
2
|
+
import { Effect, Schema, Context, Layer } from "effect";
|
|
3
|
+
import { EffectFlock } from "./effect-flock.js";
|
|
4
|
+
declare const InstallFailedError_base: Schema.Class<InstallFailedError, Schema.TaggedStruct<"NpmInstallFailedError", {
|
|
5
|
+
readonly add: Schema.optional<Schema.$Array<Schema.String>>;
|
|
6
|
+
readonly dir: Schema.String;
|
|
7
|
+
readonly cause: Schema.optional<Schema.Defect>;
|
|
8
|
+
}>, import("effect/Cause").YieldableError>;
|
|
9
|
+
export declare class InstallFailedError extends InstallFailedError_base {
|
|
10
|
+
get message(): string;
|
|
11
|
+
}
|
|
12
|
+
export interface Package {
|
|
13
|
+
readonly directory: string;
|
|
14
|
+
readonly name: string;
|
|
15
|
+
readonly version?: string;
|
|
16
|
+
readonly revision?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface Interface {
|
|
19
|
+
readonly add: (pkg: string) => Effect.Effect<Package, InstallFailedError | EffectFlock.LockError>;
|
|
20
|
+
readonly resolve: (pkg: string) => Effect.Effect<Package>;
|
|
21
|
+
readonly check: (pkg: string) => Effect.Effect<boolean, InstallFailedError>;
|
|
22
|
+
readonly update: (pkg: string) => Effect.Effect<Package, InstallFailedError | EffectFlock.LockError>;
|
|
23
|
+
/**
|
|
24
|
+
* Whether newer versions should install on their own because the package names what to follow: `name@latest`, a
|
|
25
|
+
* version range, a Git `semver:` range, or a Git ref the remote lists as a branch. A bare name or repository, other
|
|
26
|
+
* dist-tags, Git tags and commits stay on what's installed.
|
|
27
|
+
*/
|
|
28
|
+
readonly follows: (pkg: string) => Effect.Effect<boolean, InstallFailedError>;
|
|
29
|
+
/**
|
|
30
|
+
* Stop using the newest installed version when it is `version`, so the previous one is current again. Its files stay
|
|
31
|
+
* until they expire, for anything still running it. False when it isn't the newest or there is no previous one.
|
|
32
|
+
*/
|
|
33
|
+
readonly reject: (pkg: string, version: string) => Effect.Effect<boolean, InstallFailedError | EffectFlock.LockError>;
|
|
34
|
+
readonly which: (pkg: string, bin?: string) => Effect.Effect<string | undefined>;
|
|
35
|
+
}
|
|
36
|
+
declare const Service_base: Context.ServiceClass<Service, "@radheim/Npm", Interface>;
|
|
37
|
+
export declare class Service extends Service_base {
|
|
38
|
+
}
|
|
39
|
+
export declare function sanitize(pkg: string): string;
|
|
40
|
+
export declare function isRegistryPackage(pkg: string): Promise<boolean>;
|
|
41
|
+
export declare function isInstallablePackage(pkg: string): Promise<boolean>;
|
|
42
|
+
export declare function cacheKey(pkg: string): Promise<string>;
|
|
43
|
+
export declare const unsupportedService: Interface;
|
|
44
|
+
export declare const unsupportedLayer: Layer.Layer<Service, never, never>;
|
|
45
|
+
export declare const node: import("./effect/layer-node.js").Provider<Service, never, import("./effect/layer-node.js").Tag<"global">, true>;
|