@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,21 @@
1
+ export declare function activityCalendar(input: {
2
+ activity: readonly {
3
+ date: string;
4
+ steps: number;
5
+ }[];
6
+ from: number;
7
+ to: number;
8
+ maxWeeks: number;
9
+ }): {
10
+ weeks: {
11
+ date: string;
12
+ steps: number;
13
+ level: number;
14
+ }[][];
15
+ months: {
16
+ span: number;
17
+ week: number;
18
+ label: string;
19
+ }[];
20
+ clipped: boolean;
21
+ };
@@ -0,0 +1,42 @@
1
+ export function activityCalendar(input) {
2
+ // Extract local dates first, then use UTC ordinals so DST cannot add or drop cells.
3
+ const ordinal = (time) => {
4
+ const date = new Date(time);
5
+ return Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()) / 86_400_000;
6
+ };
7
+ const from = ordinal(input.from);
8
+ const to = ordinal(input.to - 1);
9
+ const monday = from - ((new Date(from * 86_400_000).getUTCDay() + 6) % 7);
10
+ const total = input.to <= input.from ? 0 : Math.floor((to - monday) / 7) + 1;
11
+ const count = Math.min(total, 53, Math.max(1, Math.floor(input.maxWeeks)));
12
+ const start = monday + Math.max(0, total - count) * 7;
13
+ const values = new Map(input.activity.map((day) => [day.date, day.steps]));
14
+ const levels = [...new Set([...values.values()].filter((steps) => steps > 0))].sort((a, b) => a - b);
15
+ const weeks = Array.from({ length: count }, (_, week) => Array.from({ length: 7 }, (_, day) => {
16
+ const date = start + week * 7 + day;
17
+ const key = new Date(date * 86_400_000).toISOString().slice(0, 10);
18
+ const steps = values.get(key) ?? 0;
19
+ return {
20
+ date: key,
21
+ steps,
22
+ level: date < from || date > to
23
+ ? -1
24
+ : steps === 0
25
+ ? 0
26
+ : Math.max(1, Math.ceil(((levels.indexOf(steps) + 1) / levels.length) * 4)),
27
+ };
28
+ }));
29
+ const formatter = new Intl.DateTimeFormat("en-US", { month: "short", timeZone: "UTC" });
30
+ // Thursday identifies the month owning most of a week; partial edge weeks stay inside the range.
31
+ const months = weeks
32
+ .map((_, week) => ({
33
+ week,
34
+ label: formatter.format(Math.min(to, Math.max(from, start + week * 7 + 3)) * 86_400_000),
35
+ }))
36
+ .filter((month, index, months) => index === 0 || month.label !== months[index - 1].label);
37
+ return {
38
+ weeks,
39
+ months: months.map((month, index) => ({ ...month, span: (months[index + 1]?.week ?? count) - month.week })),
40
+ clipped: count < total,
41
+ };
42
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,119 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { activityCalendar } from "./activity-calendar.js";
3
+ const input = {
4
+ from: new Date(2026, 0, 1).getTime(),
5
+ to: new Date(2026, 0, 8).getTime(),
6
+ maxWeeks: 53,
7
+ activity: [
8
+ { date: "2026-01-01", steps: 1 },
9
+ { date: "2026-01-02", steps: 50 },
10
+ ],
11
+ };
12
+ describe("activity calendar", () => {
13
+ test("aligns Monday-first weeks and excludes cells outside the end-exclusive range", () => {
14
+ const calendar = activityCalendar(input);
15
+ expect(calendar.clipped).toBe(false);
16
+ expect(calendar.weeks).toHaveLength(2);
17
+ expect(calendar.weeks[0][0]).toEqual({ date: "2025-12-29", steps: 0, level: -1 });
18
+ expect(calendar.weeks[0][3]).toEqual({ date: "2026-01-01", steps: 1, level: 2 });
19
+ expect(calendar.weeks[0][4]).toEqual({ date: "2026-01-02", steps: 50, level: 4 });
20
+ expect(calendar.weeks[1][2]).toEqual({ date: "2026-01-07", steps: 0, level: 0 });
21
+ expect(calendar.weeks[1][3].level).toBe(-1);
22
+ expect(calendar.months).toEqual([{ week: 0, label: "Jan", span: 2 }]);
23
+ });
24
+ test("clips to the latest weeks and keeps empty days distinct from out-of-range cells", () => {
25
+ const calendar = activityCalendar({ ...input, activity: [], maxWeeks: 1 });
26
+ expect(calendar.clipped).toBe(true);
27
+ expect(calendar.weeks).toHaveLength(1);
28
+ expect(calendar.weeks[0][0]).toEqual({ date: "2026-01-05", steps: 0, level: 0 });
29
+ expect(calendar.weeks[0][3].level).toBe(-1);
30
+ });
31
+ test("caps long histories at 53 weeks", () => {
32
+ const calendar = activityCalendar({ ...input, from: new Date(2020, 0, 1).getTime(), maxWeeks: 200 });
33
+ expect(calendar.clipped).toBe(true);
34
+ expect(calendar.weeks).toHaveLength(53);
35
+ expect(calendar.weeks.at(-1)?.[2].date).toBe("2026-01-07");
36
+ expect(calendar.months.reduce((sum, month) => sum + month.span, 0)).toBe(53);
37
+ });
38
+ test("returns month positions and spans for partial first and last months", () => {
39
+ const calendar = activityCalendar({
40
+ ...input,
41
+ from: new Date(2026, 3, 29).getTime(),
42
+ to: new Date(2026, 4, 20).getTime(),
43
+ });
44
+ expect(calendar.months).toEqual([
45
+ { week: 0, label: "Apr", span: 1 },
46
+ { week: 1, label: "May", span: 3 },
47
+ ]);
48
+ const partial = activityCalendar({
49
+ ...input,
50
+ from: new Date(2026, 3, 1).getTime(),
51
+ to: new Date(2026, 3, 2).getTime(),
52
+ });
53
+ expect(partial.months).toEqual([{ week: 0, label: "Apr", span: 1 }]);
54
+ });
55
+ test("places month labels across a year boundary", () => {
56
+ const calendar = activityCalendar({
57
+ ...input,
58
+ from: new Date(2025, 11, 22).getTime(),
59
+ to: new Date(2026, 0, 12).getTime(),
60
+ });
61
+ expect(calendar.months).toEqual([
62
+ { week: 0, label: "Dec", span: 1 },
63
+ { week: 1, label: "Jan", span: 2 },
64
+ ]);
65
+ });
66
+ test("keeps exactly seven distinct cells per week across DST and leap days", () => {
67
+ const calendar = activityCalendar({
68
+ from: new Date(2024, 1, 26).getTime(),
69
+ to: new Date(2024, 2, 12).getTime(),
70
+ maxWeeks: 53,
71
+ activity: [
72
+ { date: "2024-02-29", steps: 1 },
73
+ { date: "2024-03-10", steps: 1 },
74
+ ],
75
+ });
76
+ expect(calendar.weeks).toHaveLength(3);
77
+ expect(calendar.weeks
78
+ .flat()
79
+ .filter((day) => day.steps > 0)
80
+ .map((day) => day.date)).toEqual(["2024-02-29", "2024-03-10"]);
81
+ expect(new Set(calendar.weeks.flat().map((day) => day.date)).size).toBe(21);
82
+ });
83
+ test("uses the highest intensity for a single distinct positive count", () => {
84
+ const calendar = activityCalendar({ ...input, activity: input.activity.map((day) => ({ ...day, steps: 10 })) });
85
+ expect(calendar.weeks
86
+ .flat()
87
+ .filter((day) => day.steps > 0)
88
+ .map((day) => day.level)).toEqual([4, 4]);
89
+ });
90
+ test("ranks distinct activity counts in four levels", () => {
91
+ const calendar = activityCalendar({
92
+ ...input,
93
+ to: new Date(2026, 0, 10).getTime(),
94
+ activity: Array.from({ length: 8 }, (_, index) => ({ date: `2026-01-0${index + 1}`, steps: index + 1 })),
95
+ });
96
+ expect(calendar.weeks
97
+ .flat()
98
+ .filter((day) => day.steps > 0)
99
+ .map((day) => day.level)).toEqual([1, 1, 2, 2, 3, 3, 4, 4]);
100
+ });
101
+ test("keeps intensity relative to the requested range when older weeks are clipped", () => {
102
+ const calendar = activityCalendar({
103
+ ...input,
104
+ maxWeeks: 1,
105
+ activity: [
106
+ { date: "2026-01-01", steps: 50 },
107
+ { date: "2026-01-05", steps: 1 },
108
+ ],
109
+ });
110
+ expect(calendar.weeks[0][0].level).toBe(2);
111
+ });
112
+ test("returns an empty calendar for an empty range", () => {
113
+ expect(activityCalendar({ ...input, to: input.from, activity: [] })).toEqual({
114
+ weeks: [],
115
+ months: [],
116
+ clipped: false,
117
+ });
118
+ });
119
+ });
@@ -0,0 +1,7 @@
1
+ export declare namespace Binary {
2
+ function search<T>(array: T[], id: string, compare: (item: T) => string): {
3
+ found: boolean;
4
+ index: number;
5
+ };
6
+ function insert<T>(array: T[], item: T, compare: (item: T) => string): T[];
7
+ }
package/dist/binary.js ADDED
@@ -0,0 +1,34 @@
1
+ export var Binary;
2
+ (function (Binary) {
3
+ function search(array, id, compare) {
4
+ let left = 0;
5
+ let right = array.length - 1;
6
+ while (left <= right) {
7
+ const middle = Math.floor((left + right) / 2);
8
+ const value = compare(array[middle]);
9
+ if (value === id)
10
+ return { found: true, index: middle };
11
+ if (value < id)
12
+ left = middle + 1;
13
+ else
14
+ right = middle - 1;
15
+ }
16
+ return { found: false, index: left };
17
+ }
18
+ Binary.search = search;
19
+ function insert(array, item, compare) {
20
+ const id = compare(item);
21
+ let left = 0;
22
+ let right = array.length;
23
+ while (left < right) {
24
+ const middle = Math.floor((left + right) / 2);
25
+ if (compare(array[middle]) < id)
26
+ left = middle + 1;
27
+ else
28
+ right = middle;
29
+ }
30
+ array.splice(left, 0, item);
31
+ return array;
32
+ }
33
+ Binary.insert = insert;
34
+ })(Binary || (Binary = {}));
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,16 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { Binary } from "./binary.js";
3
+ describe("binary search", () => {
4
+ test("finds sorted values and their insertion points", () => {
5
+ const values = [{ id: "a" }, { id: "c" }, { id: "e" }];
6
+ expect(Binary.search(values, "c", (item) => item.id)).toEqual({ found: true, index: 1 });
7
+ expect(Binary.search(values, "d", (item) => item.id)).toEqual({ found: false, index: 2 });
8
+ expect(Binary.search(values, "0", (item) => item.id)).toEqual({ found: false, index: 0 });
9
+ });
10
+ test("inserts before the first matching sorted value", () => {
11
+ const values = [{ id: "a" }, { id: "c" }, { id: "c" }, { id: "e" }];
12
+ const item = { id: "c" };
13
+ expect(Binary.insert(values, item, (value) => value.id)).toBe(values);
14
+ expect(values).toEqual([{ id: "a" }, item, { id: "c" }, { id: "c" }, { id: "e" }]);
15
+ });
16
+ });
package/dist/bom.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ export * as Bom from "./bom.js";
2
+ import { Effect } from "effect";
3
+ import type { FSUtil } from "./fs-util.js";
4
+ export declare function split(text: string): {
5
+ bom: boolean;
6
+ text: string;
7
+ };
8
+ export declare function join(text: string, bom: boolean): string;
9
+ export declare function has(content: Uint8Array): boolean;
10
+ export declare function decodeBytes(content: Uint8Array): {
11
+ bom: boolean;
12
+ text: string;
13
+ };
14
+ export declare function syncBytes(content: Uint8Array, bom: boolean): {
15
+ text: string;
16
+ bytes: Uint8Array<ArrayBufferLike> | undefined;
17
+ };
18
+ export declare const readFile: (fs: FSUtil.Interface, filepath: string) => Effect.Effect<{
19
+ bom: boolean;
20
+ text: string;
21
+ }, import("effect/PlatformError").PlatformError, never>;
22
+ export declare const syncFile: (fs: FSUtil.Interface, filepath: string, bom: boolean) => Effect.Effect<string, FSUtil.Error, never>;
package/dist/bom.js ADDED
@@ -0,0 +1,36 @@
1
+ export * as Bom from "./bom.js";
2
+ import { Effect } from "effect";
3
+ const code = 0xfeff;
4
+ const value = String.fromCharCode(code);
5
+ export function split(text) {
6
+ const stripped = text.replace(/^\uFEFF+/, "");
7
+ return { bom: stripped.length !== text.length, text: stripped };
8
+ }
9
+ export function join(text, bom) {
10
+ const stripped = split(text).text;
11
+ return bom ? value + stripped : stripped;
12
+ }
13
+ export function has(content) {
14
+ return content[0] === 0xef && content[1] === 0xbb && content[2] === 0xbf;
15
+ }
16
+ export function decodeBytes(content) {
17
+ return split(decode(content));
18
+ }
19
+ export function syncBytes(content, bom) {
20
+ const decoded = decode(content);
21
+ const current = split(decoded);
22
+ const canonical = bom ? value + current.text : current.text;
23
+ return { text: current.text, bytes: decoded === canonical ? undefined : new TextEncoder().encode(canonical) };
24
+ }
25
+ export const readFile = Effect.fn("Bom.readFile")(function* (fs, filepath) {
26
+ return decodeBytes(yield* fs.readFile(filepath));
27
+ });
28
+ export const syncFile = Effect.fn("Bom.syncFile")(function* (fs, filepath, bom) {
29
+ const synced = syncBytes(yield* fs.readFile(filepath), bom);
30
+ if (synced.bytes)
31
+ yield* fs.writeWithDirs(filepath, synced.bytes);
32
+ return synced.text;
33
+ });
34
+ function decode(content) {
35
+ return new TextDecoder("utf-8", { ignoreBOM: true }).decode(content);
36
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,19 @@
1
+ import { expect, test } from "bun:test";
2
+ import { Bom } from "./bom.js";
3
+ test.each([
4
+ { prefix: "", bom: false, expected: undefined },
5
+ { prefix: "", bom: true, expected: "\uFEFF" },
6
+ { prefix: "\uFEFF", bom: false, expected: "" },
7
+ { prefix: "\uFEFF", bom: true, expected: undefined },
8
+ { prefix: "\uFEFF\uFEFF", bom: false, expected: "" },
9
+ { prefix: "\uFEFF\uFEFF", bom: true, expected: "\uFEFF" },
10
+ ])("syncBytes(%j)", (row) => {
11
+ const encoder = new TextEncoder();
12
+ const text = "a\uFEFF\u00e9";
13
+ const input = encoder.encode(row.prefix + text);
14
+ expect(Bom.syncBytes(input, row.bom)).toEqual({
15
+ text,
16
+ bytes: row.expected === undefined ? undefined : encoder.encode(row.expected + text),
17
+ });
18
+ expect(input).toEqual(encoder.encode(row.prefix + text));
19
+ });
@@ -0,0 +1,3 @@
1
+ import { ChildProcessSpawner } from "effect/unstable/process/ChildProcessSpawner";
2
+ export declare const node: import("./effect/layer-node.js").Provider<ChildProcessSpawner, never, import("./effect/layer-node.js").Tag<"global">>;
3
+ export * as CrossSpawnSpawner from "./cross-spawn-spawner.js";