@opencode/util 0.0.0-reserved → 2.0.1

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.
Files changed (82) hide show
  1. package/dist/activity-calendar.d.ts +21 -0
  2. package/dist/activity-calendar.js +42 -0
  3. package/dist/activity-calendar.test.d.ts +1 -0
  4. package/dist/activity-calendar.test.js +119 -0
  5. package/dist/binary.d.ts +7 -0
  6. package/dist/binary.js +34 -0
  7. package/dist/binary.test.d.ts +1 -0
  8. package/dist/binary.test.js +16 -0
  9. package/dist/bom.d.ts +22 -0
  10. package/dist/bom.js +36 -0
  11. package/dist/bom.test.d.ts +1 -0
  12. package/dist/bom.test.js +19 -0
  13. package/dist/cross-spawn-spawner.d.ts +3 -0
  14. package/dist/cross-spawn-spawner.js +438 -0
  15. package/dist/effect/app-node-platform.d.ts +6 -0
  16. package/dist/effect/app-node-platform.js +11 -0
  17. package/dist/effect/app-node.d.ts +62 -0
  18. package/dist/effect/app-node.js +8 -0
  19. package/dist/effect/layer-node.d.ts +135 -0
  20. package/dist/effect/layer-node.js +156 -0
  21. package/dist/effect/memo-map.d.ts +2 -0
  22. package/dist/effect/memo-map.js +2 -0
  23. package/dist/effect/runtime.d.ts +8 -0
  24. package/dist/effect/runtime.js +16 -0
  25. package/dist/effect/service-use.d.ts +7 -0
  26. package/dist/effect/service-use.js +27 -0
  27. package/dist/effect-flock.d.ts +31 -0
  28. package/dist/effect-flock.js +186 -0
  29. package/dist/encode.d.ts +4 -0
  30. package/dist/encode.js +38 -0
  31. package/dist/encode.test.d.ts +1 -0
  32. package/dist/encode.test.js +23 -0
  33. package/dist/flock.d.ts +30 -0
  34. package/dist/flock.js +273 -0
  35. package/dist/fs-util.d.ts +137 -0
  36. package/dist/fs-util.js +211 -0
  37. package/dist/glob.d.ts +12 -0
  38. package/dist/glob.js +26 -0
  39. package/dist/global-roots.d.ts +8 -0
  40. package/dist/global-roots.js +17 -0
  41. package/dist/global-roots.workerd.d.ts +7 -0
  42. package/dist/global-roots.workerd.js +15 -0
  43. package/dist/global.d.ts +30 -0
  44. package/dist/global.js +54 -0
  45. package/dist/hash.d.ts +4 -0
  46. package/dist/hash.js +12 -0
  47. package/dist/npm-config.d.ts +4 -0
  48. package/dist/npm-config.js +34 -0
  49. package/dist/npm.d.ts +37 -0
  50. package/dist/npm.js +386 -0
  51. package/dist/observability/logging.d.ts +14 -0
  52. package/dist/observability/logging.js +151 -0
  53. package/dist/observability/otlp.d.ts +18 -0
  54. package/dist/observability/otlp.js +76 -0
  55. package/dist/observability/shared.d.ts +1 -0
  56. package/dist/observability/shared.js +7 -0
  57. package/dist/observability.d.ts +13 -0
  58. package/dist/observability.js +37 -0
  59. package/dist/patch.d.ts +43 -0
  60. package/dist/patch.js +331 -0
  61. package/dist/path.d.ts +4 -0
  62. package/dist/path.js +33 -0
  63. package/dist/path.test.d.ts +1 -0
  64. package/dist/path.test.js +36 -0
  65. package/dist/process.d.ts +54 -0
  66. package/dist/process.js +167 -0
  67. package/dist/retry.d.ts +8 -0
  68. package/dist/retry.js +37 -0
  69. package/dist/retry.test.d.ts +1 -0
  70. package/dist/retry.test.js +31 -0
  71. package/dist/runtime/import.bun.d.ts +2 -0
  72. package/dist/runtime/import.bun.js +8 -0
  73. package/dist/runtime/import.node.d.ts +2 -0
  74. package/dist/runtime/import.node.js +62 -0
  75. package/dist/runtime/import.workerd.d.ts +2 -0
  76. package/dist/runtime/import.workerd.js +7 -0
  77. package/dist/runtime-import.d.ts +1 -0
  78. package/dist/runtime-import.js +1 -0
  79. package/dist/session-title-fallback.d.ts +16 -0
  80. package/dist/session-title-fallback.js +23 -0
  81. package/package.json +66 -6
  82. package/README.md +0 -5
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,31 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { retry } from "./retry.js";
3
+ describe("client retry", () => {
4
+ test("retries transient failures up to the configured attempt count", async () => {
5
+ const failures = [];
6
+ const value = await retry(async () => {
7
+ failures.push("attempt");
8
+ if (failures.length < 3)
9
+ throw new Error("Failed to fetch");
10
+ return "ready";
11
+ }, { delay: 0 });
12
+ expect(value).toBe("ready");
13
+ expect(failures).toHaveLength(3);
14
+ });
15
+ test("does not retry other failures", async () => {
16
+ const failures = [];
17
+ await expect(retry(async () => {
18
+ failures.push("attempt");
19
+ throw new Error("invalid response");
20
+ })).rejects.toThrow("invalid response");
21
+ expect(failures).toHaveLength(1);
22
+ });
23
+ test("uses a caller-owned retry condition", async () => {
24
+ const failures = [];
25
+ await expect(retry(async () => {
26
+ failures.push("attempt");
27
+ throw new Error("retry me");
28
+ }, { attempts: 2, delay: 0, retryIf: () => true })).rejects.toThrow("retry me");
29
+ expect(failures).toHaveLength(2);
30
+ });
31
+ });
@@ -0,0 +1,2 @@
1
+ export declare function importModule(specifier: string): Promise<unknown>;
2
+ export declare function resolveModule(specifier: string, directory: string): string;
@@ -0,0 +1,8 @@
1
+ import { pathToFileURL } from "node:url";
2
+ export function importModule(specifier) {
3
+ return import(specifier);
4
+ }
5
+ export function resolveModule(specifier, directory) {
6
+ const resolved = Bun.resolveSync(specifier, directory);
7
+ return resolved.startsWith("node:") ? resolved : pathToFileURL(resolved).href;
8
+ }
@@ -0,0 +1,2 @@
1
+ export declare function importModule(specifier: string): Promise<unknown>;
2
+ export declare function resolveModule(specifier: string, directory: string): string;
@@ -0,0 +1,62 @@
1
+ import { Script, constants } from "node:vm";
2
+ import { registerHooks } from "node:module";
3
+ import { statSync } from "node:fs";
4
+ import path from "node:path";
5
+ import { pathToFileURL } from "node:url";
6
+ export async function importModule(specifier) {
7
+ const imported = (await new Script(`import(${JSON.stringify(specifier)})`, {
8
+ importModuleDynamically: constants.USE_MAIN_CONTEXT_DEFAULT_LOADER,
9
+ }).runInThisContext());
10
+ if (typeof imported !== "object" || imported === null)
11
+ return imported;
12
+ const module = imported;
13
+ const exports = module["module.exports"];
14
+ if (exports !== module.default || (typeof exports !== "object" && typeof exports !== "function") || exports === null)
15
+ return imported;
16
+ return Object.assign({}, module, exports);
17
+ }
18
+ export function resolveModule(specifier, directory) {
19
+ // Node only accepts import.meta.resolve's parent URL behind an experimental
20
+ // flag. Scope this synchronous resolution to the caller's package directory
21
+ // through the supported resolver hook instead.
22
+ const hook = registerHooks({
23
+ resolve(specifier, context, nextResolve) {
24
+ return nextResolve(specifier, { ...context, parentURL: pathToFileURL(path.join(directory, "package.json")).href });
25
+ },
26
+ });
27
+ try {
28
+ const resolve = (target) => {
29
+ const resolved = import.meta.resolve(path.isAbsolute(target) ? pathToFileURL(target).href : target);
30
+ if (resolved.startsWith("file:"))
31
+ statSync(new URL(resolved));
32
+ return resolved;
33
+ };
34
+ try {
35
+ return resolve(specifier);
36
+ }
37
+ catch (error) {
38
+ if (path.extname(specifier) || !missing(error))
39
+ throw error;
40
+ // Node does not infer extensions for local files or legacy package
41
+ // subpaths. Resolve each candidate natively so package exports still apply.
42
+ for (const extension of [".ts", ".tsx", ".js", ".jsx", ".mts", ".mjs", ".cts", ".cjs"]) {
43
+ try {
44
+ return resolve(specifier + extension);
45
+ }
46
+ catch (cause) {
47
+ if (!missing(cause))
48
+ throw cause;
49
+ }
50
+ }
51
+ throw error;
52
+ }
53
+ }
54
+ finally {
55
+ hook.deregister();
56
+ }
57
+ }
58
+ function missing(error) {
59
+ return (error instanceof Error &&
60
+ "code" in error &&
61
+ ["ENOENT", "ENOTDIR", "ERR_MODULE_NOT_FOUND"].includes(String(error.code)));
62
+ }
@@ -0,0 +1,2 @@
1
+ export declare function importModule(_specifier: string): Promise<unknown>;
2
+ export declare function resolveModule(_specifier: string, _directory: string): string;
@@ -0,0 +1,7 @@
1
+ const unavailable = () => new Error("Dynamic module loading is unavailable on workerd");
2
+ export function importModule(_specifier) {
3
+ return Promise.reject(unavailable());
4
+ }
5
+ export function resolveModule(_specifier, _directory) {
6
+ throw unavailable();
7
+ }
@@ -0,0 +1 @@
1
+ export { importModule, resolveModule } from "#runtime-import";
@@ -0,0 +1 @@
1
+ export { importModule, resolveModule } from "#runtime-import";
@@ -0,0 +1,16 @@
1
+ export * as SessionTitleFallback from "./session-title-fallback.js";
2
+ interface Info {
3
+ readonly title?: string;
4
+ readonly parentID?: string;
5
+ readonly time: {
6
+ readonly created: number;
7
+ };
8
+ }
9
+ /** Supplies the timestamped title required by compatibility surfaces. */
10
+ export declare function withTimestampedFallback(info: Info): string;
11
+ /** Supplies a compact human label and collapses historical timestamped fallbacks. */
12
+ export declare function displayLabel(info: Pick<Info, "title" | "parentID">): string;
13
+ /** Recognizes missing and historical root or child fallback titles. */
14
+ export declare function isFallbackTitle(title?: string): boolean;
15
+ /** Recognizes a missing title or the exact root fallback for this session. */
16
+ export declare function isExactRootFallback(info: Pick<Info, "title" | "time">): boolean;
@@ -0,0 +1,23 @@
1
+ export * as SessionTitleFallback from "./session-title-fallback.js";
2
+ const pattern = /^(New session|Child session) - \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/;
3
+ /** Supplies the timestamped title required by compatibility surfaces. */
4
+ export function withTimestampedFallback(info) {
5
+ return info.title ?? fallback(info);
6
+ }
7
+ /** Supplies a compact human label and collapses historical timestamped fallbacks. */
8
+ export function displayLabel(info) {
9
+ if (!info.title)
10
+ return info.parentID ? "Child session" : "New session";
11
+ return info.title.match(pattern)?.[1] ?? info.title;
12
+ }
13
+ /** Recognizes missing and historical root or child fallback titles. */
14
+ export function isFallbackTitle(title) {
15
+ return title === undefined || pattern.test(title);
16
+ }
17
+ /** Recognizes a missing title or the exact root fallback for this session. */
18
+ export function isExactRootFallback(info) {
19
+ return info.title === undefined || info.title === fallback({ time: info.time });
20
+ }
21
+ function fallback(info) {
22
+ return `${info.parentID ? "Child" : "New"} session - ${new Date(info.time.created).toISOString()}`;
23
+ }
package/package.json CHANGED
@@ -1,15 +1,75 @@
1
1
  {
2
+ "$schema": "https://json.schemastore.org/package.json",
2
3
  "name": "@opencode/util",
3
- "version": "0.0.0-reserved",
4
- "description": "OpenCode package bootstrap — not a functional release",
4
+ "version": "2.0.1",
5
+ "type": "module",
5
6
  "license": "MIT",
6
7
  "repository": {
7
8
  "type": "git",
8
- "url": "git+https://github.com/anomalyco/opencode.git"
9
+ "url": "git+https://github.com/anomalyco/opencode.git",
10
+ "directory": "packages/util"
9
11
  },
10
12
  "publishConfig": {
11
- "registry": "https://registry.npmjs.org",
12
- "access": "public",
13
- "tag": "reserved"
13
+ "access": "public"
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "exports": {
19
+ "./effect/layer-node": {
20
+ "import": "./dist/effect/layer-node.js",
21
+ "types": "./dist/effect/layer-node.d.ts"
22
+ },
23
+ "./*": {
24
+ "import": "./dist/*.js",
25
+ "types": "./dist/*.d.ts"
26
+ }
27
+ },
28
+ "imports": {
29
+ "#global-roots": {
30
+ "workerd": "./dist/global-roots.workerd.js",
31
+ "default": "./dist/global-roots.js"
32
+ },
33
+ "#runtime-import": {
34
+ "workerd": "./dist/runtime/import.workerd.js",
35
+ "bun": "./dist/runtime/import.bun.js",
36
+ "node": "./dist/runtime/import.node.js",
37
+ "default": "./dist/runtime/import.bun.js"
38
+ }
39
+ },
40
+ "scripts": {
41
+ "build": "bun run script/build.ts",
42
+ "test": "bun test --only-failures",
43
+ "typecheck": "tsgo --noEmit",
44
+ "typecheck:dist": "bun run build && bun typecheck --project tsconfig.dist.json"
45
+ },
46
+ "dependencies": {
47
+ "@effect/opentelemetry": "4.0.0-rc.112",
48
+ "@effect/platform-node": "4.0.0-rc.112",
49
+ "@effect/platform-node-shared": "4.0.0-rc.112",
50
+ "@npmcli/arborist": "9.4.0",
51
+ "@npmcli/config": "10.8.1",
52
+ "@opentelemetry/api": "1.9.0",
53
+ "@opentelemetry/context-async-hooks": "2.6.1",
54
+ "@opentelemetry/exporter-trace-otlp-http": "0.214.0",
55
+ "@opentelemetry/sdk-trace-base": "2.6.1",
56
+ "@opentelemetry/sdk-trace-node": "2.6.1",
57
+ "cross-spawn": "7.0.6",
58
+ "effect": "4.0.0-rc.112",
59
+ "glob": "13.0.5",
60
+ "mime-types": "3.0.2",
61
+ "minimatch": "10.2.5",
62
+ "npm-package-arg": "13.0.2",
63
+ "pacote": "21.5.1"
64
+ },
65
+ "devDependencies": {
66
+ "@tsconfig/bun": "1.0.9",
67
+ "@types/bun": "1.4.0",
68
+ "@types/cross-spawn": "6.0.6",
69
+ "@types/node": "24.12.2",
70
+ "@types/npm-package-arg": "6.1.4",
71
+ "@types/npmcli__arborist": "6.3.3",
72
+ "@types/pacote": "11.1.8",
73
+ "@typescript/native-preview": "7.0.0-dev.20251207.1"
14
74
  }
15
75
  }
package/README.md DELETED
@@ -1,5 +0,0 @@
1
- # @opencode/util
2
-
3
- Bootstrap placeholder for the official [OpenCode](https://opencode.ai) release pipeline.
4
-
5
- This version contains no implementation or executable. Do not use it as a functional release.