@opencode/util 0.0.0-dev-21614 → 0.0.0-dev-21627

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.
@@ -0,0 +1,11 @@
1
+ import { Effect } from "effect";
2
+ /**
3
+ * Writes a V8 heap snapshot of this process into `directory` and returns once the file is complete.
4
+ * Blocks the event loop while the heap serializes. The file can contain secrets, so it is created
5
+ * owner-only before the runtime writes into it.
6
+ */
7
+ export declare const write: (directory: string) => Effect.Effect<{
8
+ path: string;
9
+ pid: number;
10
+ }, import("effect/Cause").UnknownError, never>;
11
+ export * as HeapSnapshot from "./heap-snapshot.js";
@@ -0,0 +1,26 @@
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.
9
+ * Blocks the event loop while the heap serializes. The file can contain secrets, so it is created
10
+ * owner-only before the runtime writes into it.
11
+ */
12
+ export const write = Effect.fn("HeapSnapshot.write")(function* (directory) {
13
+ const v8 = yield* Effect.tryPromise(() => import("node:v8"));
14
+ const time = new Date(yield* Clock.currentTimeMillis).toISOString().replace(/[:.]/g, "");
15
+ const file = path.join(directory, `heap-${process.pid}-${time}.heapsnapshot`);
16
+ yield* Effect.tryPromise(async () => {
17
+ await mkdir(directory, { recursive: true });
18
+ const handle = await open(file, "wx", 0o600);
19
+ await handle.close();
20
+ });
21
+ yield* Effect.logInfo("writing heap snapshot", { path: file });
22
+ yield* Effect.try(() => v8.writeHeapSnapshot(file));
23
+ yield* Effect.logInfo("heap snapshot written", { path: file });
24
+ return { path: file, pid: process.pid };
25
+ }, (effect) => lock.withPermit(effect));
26
+ export * as HeapSnapshot from "./heap-snapshot.js";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@opencode/util",
4
- "version": "0.0.0-dev-21614",
4
+ "version": "0.0.0-dev-21627",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "repository": {