@oh-my-pi/pi-utils 18.1.21 → 18.2.0
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/CHANGELOG.md +30 -0
- package/THIRD-PARTY-NOTICES.txt +54 -25
- package/dist/types/async.d.ts +25 -0
- package/dist/types/browsers.d.ts +2 -30
- package/dist/types/dirs.d.ts +10 -0
- package/dist/types/env.d.ts +2 -2
- package/dist/types/fetch-retry.d.ts +2 -1
- package/dist/types/index.d.ts +0 -1
- package/dist/types/peek-file.d.ts +2 -3
- package/package.json +2 -2
- package/src/async.ts +37 -0
- package/src/browsers.ts +10 -169
- package/src/dirs.ts +17 -5
- package/src/env.ts +7 -33
- package/src/fetch-retry.ts +58 -8
- package/src/index.ts +0 -1
- package/src/logger.ts +14 -1
- package/src/peek-file.ts +17 -67
- package/src/postmortem.ts +6 -6
- package/src/stream.ts +29 -16
- package/dist/types/glob.d.ts +0 -28
- package/src/glob.ts +0 -189
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,36 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [18.2.0] - 2026-09-15
|
|
6
|
+
|
|
7
|
+
### Breaking Changes
|
|
8
|
+
|
|
9
|
+
- Removed the unused `globPaths`, `loadGitignorePatterns`, and `GlobPathsOptions` exports.
|
|
10
|
+
- Browser helpers now manage Chrome only: removed `Browser`, `BrowserTag`, `resolveBuildId()`, `getInstalledBrowsers()`, and `browser` options/metadata; `getDownloadUrl()` now takes `(platform, buildId, baseUrl?)`.
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Added `relativePathWithinNormalizedRoot()` for reusing canonical paths across containment checks.
|
|
15
|
+
- Added `sleepLong()` and `MAX_TIMER_DELAY_MS`: an abortable sleep that chunks delays past the signed 32-bit timer ceiling so day-scale provider waits elapse instead of overflowing the timer.
|
|
16
|
+
|
|
17
|
+
### Changed
|
|
18
|
+
|
|
19
|
+
- Log-retention cleanup now runs after logger construction without keeping short-lived commands alive.
|
|
20
|
+
- Debugger support now loads only when SIGUSR1 requests it.
|
|
21
|
+
|
|
22
|
+
### Fixed
|
|
23
|
+
|
|
24
|
+
- Fixed `extractRetryHint` dropping OpenCode Go's `Resets in …` quota window (`45min`, `2hr 15min`, `3 days`): the `reset in` pattern now accepts `Resets` phrasing, `hr`/`day` units, and compound `2hr 15min` remainders, so exhausted Go credentials block for the server-stated window instead of the 60s heuristic guess. ([#12091](https://github.com/can1357/oh-my-pi/pull/12091) by [@H4vC](https://github.com/H4vC))
|
|
25
|
+
- Async file-peek callbacks now receive stable `Uint8Array` windows with copying `slice()` semantics.
|
|
26
|
+
- Dotenv loading now handles multiline values and escapes consistently with Bun, preventing project values from leaking into child-shell environments.
|
|
27
|
+
- SSE readers now support lone-CR line endings and CRLF split across chunks without merging or delaying events.
|
|
28
|
+
|
|
29
|
+
## [18.1.22] - 2026-09-14
|
|
30
|
+
|
|
31
|
+
### Fixed
|
|
32
|
+
|
|
33
|
+
- Fixed `extractRetryHint` sleeping hours past the provider's stated wait when a timezone-naive `reset at` timestamp overshoots the relative retry hint: the skewed stamp is now ignored instead of winning longest-wins ([#12070](https://github.com/can1357/oh-my-pi/pull/12070) by [@H4vC](https://github.com/H4vC)).
|
|
34
|
+
|
|
5
35
|
## [18.1.21] - 2026-09-14
|
|
6
36
|
|
|
7
37
|
### Added
|
package/THIRD-PARTY-NOTICES.txt
CHANGED
|
@@ -10843,7 +10843,7 @@ RUST RUNTIME DEPENDENCY LICENSES
|
|
|
10843
10843
|
|
|
10844
10844
|
Generated from Cargo.lock by cargo-about 0.8.2 in locked, offline, workspace, all-feature, all-target mode, then restricted using cargo metadata to normal and build edges reachable from the workspace (development-only edges are excluded). cargo-deny independently evaluates the complete all-target graph.
|
|
10845
10845
|
|
|
10846
|
-
Native Opus (
|
|
10846
|
+
Native Opus (opus/opusic-sys) and PCRE2 (pcre2/pcre2-sys) are covered by the exact crate license payloads below. inferno 0.12.8 is package-scoped as CDDL-1.0: its CDDL-covered source remains available in the locked crates.io source archive at https://crates.io/crates/inferno/0.12.8 and https://github.com/jonhoo/inferno. The full locked license text follows below.
|
|
10847
10847
|
|
|
10848
10848
|
-------------------------------------------------------------------------------
|
|
10849
10849
|
License: Apache License 2.0 (Apache-2.0)
|
|
@@ -12509,6 +12509,58 @@ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
12509
12509
|
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
12510
12510
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
12511
12511
|
|
|
12512
|
+
-------------------------------------------------------------------------------
|
|
12513
|
+
License: BSD 3-Clause "New" or "Revised" License (BSD-3-Clause)
|
|
12514
|
+
Used by:
|
|
12515
|
+
- opusic-sys 0.7.5 (https://github.com/DoumanAsh/opusic-sys)
|
|
12516
|
+
|
|
12517
|
+
Full license text:
|
|
12518
|
+
|
|
12519
|
+
Copyright 2001-2023 Xiph.Org, Skype Limited, Octasic,
|
|
12520
|
+
Jean-Marc Valin, Timothy B. Terriberry,
|
|
12521
|
+
CSIRO, Gregory Maxwell, Mark Borgerding,
|
|
12522
|
+
Erik de Castro Lopo, Mozilla, Amazon
|
|
12523
|
+
|
|
12524
|
+
Redistribution and use in source and binary forms, with or without
|
|
12525
|
+
modification, are permitted provided that the following conditions
|
|
12526
|
+
are met:
|
|
12527
|
+
|
|
12528
|
+
- Redistributions of source code must retain the above copyright
|
|
12529
|
+
notice, this list of conditions and the following disclaimer.
|
|
12530
|
+
|
|
12531
|
+
- Redistributions in binary form must reproduce the above copyright
|
|
12532
|
+
notice, this list of conditions and the following disclaimer in the
|
|
12533
|
+
documentation and/or other materials provided with the distribution.
|
|
12534
|
+
|
|
12535
|
+
- Neither the name of Internet Society, IETF or IETF Trust, nor the
|
|
12536
|
+
names of specific contributors, may be used to endorse or promote
|
|
12537
|
+
products derived from this software without specific prior written
|
|
12538
|
+
permission.
|
|
12539
|
+
|
|
12540
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
12541
|
+
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
12542
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
12543
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
|
12544
|
+
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
12545
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
12546
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
12547
|
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
12548
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
12549
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
12550
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
12551
|
+
|
|
12552
|
+
Opus is subject to the royalty-free patent licenses which are
|
|
12553
|
+
specified at:
|
|
12554
|
+
|
|
12555
|
+
Xiph.Org Foundation:
|
|
12556
|
+
https://datatracker.ietf.org/ipr/1524/
|
|
12557
|
+
|
|
12558
|
+
Microsoft Corporation:
|
|
12559
|
+
https://datatracker.ietf.org/ipr/1914/
|
|
12560
|
+
|
|
12561
|
+
Broadcom Corporation:
|
|
12562
|
+
https://datatracker.ietf.org/ipr/1526/
|
|
12563
|
+
|
|
12512
12564
|
-------------------------------------------------------------------------------
|
|
12513
12565
|
License: BSD 3-Clause "New" or "Revised" License (BSD-3-Clause)
|
|
12514
12566
|
Used by:
|
|
@@ -13290,29 +13342,6 @@ jurisdiction of the Federal Courts of the Northern District of
|
|
|
13290
13342
|
California and the state courts of the State of California, with
|
|
13291
13343
|
venue lying in Santa Clara County, California.
|
|
13292
13344
|
|
|
13293
|
-
-------------------------------------------------------------------------------
|
|
13294
|
-
License: ISC License (ISC)
|
|
13295
|
-
Used by:
|
|
13296
|
-
- audiopus_sys 0.2.2 (https://github.com/lakelezz/audiopus_sys.git)
|
|
13297
|
-
|
|
13298
|
-
Full license text:
|
|
13299
|
-
|
|
13300
|
-
ISC License
|
|
13301
|
-
|
|
13302
|
-
Copyright (c) 2019, Lakelezz
|
|
13303
|
-
|
|
13304
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
13305
|
-
purpose with or without fee is hereby granted, provided that the above
|
|
13306
|
-
copyright notice and this permission notice appear in all copies.
|
|
13307
|
-
|
|
13308
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
13309
|
-
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
13310
|
-
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
13311
|
-
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
13312
|
-
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
13313
|
-
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
13314
|
-
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
13315
|
-
|
|
13316
13345
|
-------------------------------------------------------------------------------
|
|
13317
13346
|
License: ISC License (ISC)
|
|
13318
13347
|
Used by:
|
|
@@ -18734,7 +18763,7 @@ DEALINGS IN THE SOFTWARE.
|
|
|
18734
18763
|
-------------------------------------------------------------------------------
|
|
18735
18764
|
License: MIT License (MIT)
|
|
18736
18765
|
Used by:
|
|
18737
|
-
- opus 0.
|
|
18766
|
+
- opus 0.4.0 (https://github.com/SpaceManiac/opus-rs)
|
|
18738
18767
|
|
|
18739
18768
|
Full license text:
|
|
18740
18769
|
|
package/dist/types/async.d.ts
CHANGED
|
@@ -1,3 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Largest delay `setTimeout` (and `timers/promises` `scheduler.wait`)
|
|
3
|
+
* accepts without 32-bit signed overflow: larger values wrap and fire
|
|
4
|
+
* almost immediately instead of sleeping. Chunk day-scale provider waits
|
|
5
|
+
* (e.g. a monthly quota reset parsed from an error hint) so the full
|
|
6
|
+
* duration elapses instead of overflowing the timer.
|
|
7
|
+
*/
|
|
8
|
+
export declare const MAX_TIMER_DELAY_MS = 2147483647;
|
|
9
|
+
/**
|
|
10
|
+
* Abortable sleep for arbitrarily long delays. Waits longer than
|
|
11
|
+
* {@link MAX_TIMER_DELAY_MS} chunk the sleep into back-to-back timer waits
|
|
12
|
+
* so no single timer overflows; an abort during any chunk rejects like
|
|
13
|
+
* `scheduler.wait`.
|
|
14
|
+
*
|
|
15
|
+
* The remainder is deliberately consumed by chunk, not recomputed from a
|
|
16
|
+
* monotonic deadline: deadline tracking never terminates under the repo's
|
|
17
|
+
* instant `scheduler.wait` mocks (retry-cap suites spy it to resolve
|
|
18
|
+
* immediately, so `deadline - performance.now()` never reaches zero and the
|
|
19
|
+
* loop spins forever). A premature native wake (Bun `uv_async_send`, see
|
|
20
|
+
* `sleepAtLeast` in `packages/agent/src/utils/yield.ts`) can therefore
|
|
21
|
+
* under-wait by the unelapsed chunk time — but that self-corrects downstream:
|
|
22
|
+
* credential blocks carry the true deadline independently of this sleep, so
|
|
23
|
+
* an early retry re-hits 429 and re-sleeps on a fresh server hint.
|
|
24
|
+
*/
|
|
25
|
+
export declare function sleepLong(delayMs: number, signal?: AbortSignal): Promise<void>;
|
|
1
26
|
/**
|
|
2
27
|
* Wrap a promise with a timeout and optional abort signal.
|
|
3
28
|
* Rejects with the given error or a new error containing the given message if
|
package/dist/types/browsers.d.ts
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
/** Behavior-compatible reimplementation of @puppeteer/browsers' used surface. */
|
|
2
|
-
/** Supported browser products. */
|
|
3
|
-
export declare enum Browser {
|
|
4
|
-
CHROME = "chrome",
|
|
5
|
-
CHROMEHEADLESSSHELL = "chrome-headless-shell",
|
|
6
|
-
CHROMIUM = "chromium",
|
|
7
|
-
FIREFOX = "firefox",
|
|
8
|
-
CHROMEDRIVER = "chromedriver"
|
|
9
|
-
}
|
|
10
1
|
/** Browser download platform identifiers. */
|
|
11
2
|
export declare enum BrowserPlatform {
|
|
12
3
|
LINUX = "linux",
|
|
@@ -16,17 +7,6 @@ export declare enum BrowserPlatform {
|
|
|
16
7
|
WIN32 = "win32",
|
|
17
8
|
WIN64 = "win64"
|
|
18
9
|
}
|
|
19
|
-
/** Chrome-for-Testing release channel tags accepted by {@link resolveBuildId}. */
|
|
20
|
-
export declare enum BrowserTag {
|
|
21
|
-
CANARY = "canary",
|
|
22
|
-
NIGHTLY = "nightly",
|
|
23
|
-
BETA = "beta",
|
|
24
|
-
DEV = "dev",
|
|
25
|
-
DEVEDITION = "devedition",
|
|
26
|
-
STABLE = "stable",
|
|
27
|
-
ESR = "esr",
|
|
28
|
-
LATEST = "latest"
|
|
29
|
-
}
|
|
30
10
|
/** Download progress reported while a browser archive is streamed to disk. */
|
|
31
11
|
export interface BrowserDownloadProgress {
|
|
32
12
|
downloadedBytes: number;
|
|
@@ -34,7 +14,6 @@ export interface BrowserDownloadProgress {
|
|
|
34
14
|
}
|
|
35
15
|
/** Inputs used to locate an installed browser executable. */
|
|
36
16
|
export interface ComputeExecutablePathOptions {
|
|
37
|
-
browser: Browser;
|
|
38
17
|
buildId: string;
|
|
39
18
|
cacheDir: string;
|
|
40
19
|
platform?: BrowserPlatform;
|
|
@@ -44,9 +23,8 @@ export interface InstallOptions extends ComputeExecutablePathOptions {
|
|
|
44
23
|
baseUrl?: string;
|
|
45
24
|
downloadProgressCallback?: (progress: BrowserDownloadProgress) => void;
|
|
46
25
|
}
|
|
47
|
-
/** Metadata for
|
|
26
|
+
/** Metadata for a managed Chrome installation in Puppeteer's cache layout. */
|
|
48
27
|
export interface InstalledBrowser {
|
|
49
|
-
browser: Browser;
|
|
50
28
|
buildId: string;
|
|
51
29
|
platform: BrowserPlatform;
|
|
52
30
|
path: string;
|
|
@@ -54,15 +32,9 @@ export interface InstalledBrowser {
|
|
|
54
32
|
}
|
|
55
33
|
/** Detect the current host's Puppeteer browser platform. */
|
|
56
34
|
export declare function detectBrowserPlatform(): BrowserPlatform | undefined;
|
|
57
|
-
/** Resolve a Chrome-for-Testing channel, milestone, or build prefix to a full build ID. */
|
|
58
|
-
export declare function resolveBuildId(browser: Browser, _platform: BrowserPlatform, tag: string | BrowserTag): Promise<string>;
|
|
59
35
|
/** Return the Chrome-for-Testing archive URL for a browser build. */
|
|
60
|
-
export declare function getDownloadUrl(
|
|
36
|
+
export declare function getDownloadUrl(platform: BrowserPlatform, buildId: string, baseUrl?: string): URL;
|
|
61
37
|
/** Compute the executable path in Puppeteer's cache layout. */
|
|
62
38
|
export declare function computeExecutablePath(options: ComputeExecutablePathOptions): string;
|
|
63
|
-
/** Scan a Puppeteer cache for browser installation directories. */
|
|
64
|
-
export declare function getInstalledBrowsers(options: {
|
|
65
|
-
cacheDir: string;
|
|
66
|
-
}): Promise<InstalledBrowser[]>;
|
|
67
39
|
/** Download and unpack Chrome into Puppeteer's existing cache layout. */
|
|
68
40
|
export declare function install(options: InstallOptions): Promise<InstalledBrowser>;
|
package/dist/types/dirs.d.ts
CHANGED
|
@@ -44,6 +44,16 @@ export declare function resolveProfileEnv(omp: string | undefined, pi: string |
|
|
|
44
44
|
export declare function getBaseConfigRoot(): string;
|
|
45
45
|
export declare function resolveEquivalentPath(inputPath: string): string;
|
|
46
46
|
export declare function normalizePathForComparison(inputPath: string): string;
|
|
47
|
+
/**
|
|
48
|
+
* Compare paths already normalized by {@link normalizePathForComparison}.
|
|
49
|
+
*
|
|
50
|
+
* Returns the relative path (an empty string when the paths are equal), or
|
|
51
|
+
* `null` when the candidate is outside the root. Callers classifying one
|
|
52
|
+
* candidate against several static roots can normalize each side once and
|
|
53
|
+
* reuse the public helpers' containment semantics without repeating realpath
|
|
54
|
+
* work.
|
|
55
|
+
*/
|
|
56
|
+
export declare function relativePathWithinNormalizedRoot(normalizedRoot: string, normalizedCandidate: string): string | null;
|
|
47
57
|
export declare function pathIsWithin(root: string, candidate: string): boolean;
|
|
48
58
|
export declare function relativePathWithinRoot(root: string, candidate: string): string | null;
|
|
49
59
|
/** Get the project directory. */
|
package/dist/types/env.d.ts
CHANGED
|
@@ -29,8 +29,8 @@ export declare function filterProcessEnv(env: Record<string, string | undefined>
|
|
|
29
29
|
/** Filters process env for child shells without launch-cwd dotenv values. */
|
|
30
30
|
export declare function filterChildShellEnv(env: Record<string, string | undefined>, cwd?: string): Record<string, string>;
|
|
31
31
|
/**
|
|
32
|
-
* Parses a .env file
|
|
33
|
-
*
|
|
32
|
+
* Parses a complete .env file with the runtime's dotenv grammar, then retains
|
|
33
|
+
* only shell-identifier names and spawn-safe values before mirroring valid
|
|
34
34
|
* `OMP_` variables to their `PI_` aliases.
|
|
35
35
|
*/
|
|
36
36
|
export declare function parseEnvFile(filePath: string): Record<string, string>;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Server-suggested retry delay extraction. Merges the patterns historically used
|
|
3
|
-
* by the OpenAI Codex and Google Gemini retry helpers.
|
|
4
3
|
*
|
|
5
4
|
* Header sources (checked in order):
|
|
6
5
|
* - `retry-after-ms` (milliseconds)
|
|
@@ -16,6 +15,8 @@
|
|
|
16
15
|
* - `try again in 250ms` / `try again in 12s` / `try again in 5 min` / `try again in ~158 min`
|
|
17
16
|
* - `retry-after-ms=98497000` / `retry-after-ms: 7200000` / `retry-after-ms = 7200000`
|
|
18
17
|
* - `Your limit will reset at 2026-09-01 09:44:51` / `将在 2026-09-01 09:44:51 重置`
|
|
18
|
+
* (offset-bearing only; a timezone-naive stamp is provider wall clock in
|
|
19
|
+
* an unknown zone and only resolves when no relative signal is present)
|
|
19
20
|
*
|
|
20
21
|
* Returns `undefined` if no signal is found, or `0` when the provider
|
|
21
22
|
* explicitly asks for an immediate retry (`retry-after…=0`, or an absolute
|
package/dist/types/index.d.ts
CHANGED
|
@@ -9,7 +9,6 @@ export * from "./file-lock.js";
|
|
|
9
9
|
export * from "./format.js";
|
|
10
10
|
export * from "./frontmatter.js";
|
|
11
11
|
export * from "./fs-error.js";
|
|
12
|
-
export * from "./glob.js";
|
|
13
12
|
export * from "./incoming-json.js";
|
|
14
13
|
export * from "./json.js";
|
|
15
14
|
export * from "./json-parse.js";
|
|
@@ -10,9 +10,8 @@ export declare function peekFile<T>(filePath: string, maxBytes: number, op: (hea
|
|
|
10
10
|
/**
|
|
11
11
|
* Read up to the last `maxBytes` of `filePath` and pass that slice to `op`.
|
|
12
12
|
*
|
|
13
|
-
* The tail mirror of {@link peekFile}:
|
|
14
|
-
*
|
|
15
|
-
* window ends at EOF. When the file is shorter than `maxBytes`, the whole file is
|
|
13
|
+
* The tail mirror of {@link peekFile}: the read is positioned at `size - len` so
|
|
14
|
+
* the window ends at EOF. When the file is shorter than `maxBytes`, the whole file is
|
|
16
15
|
* returned. A multi-byte codepoint straddling the leading cut decodes to a
|
|
17
16
|
* replacement char — callers that parse line-oriented tails drop the partial
|
|
18
17
|
* leading line anyway.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oh-my-pi/pi-utils",
|
|
3
|
-
"version": "18.
|
|
3
|
+
"version": "18.2.0",
|
|
4
4
|
"description": "Shared utilities for pi packages",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"fmt": "oxfmt --no-error-on-unmatched-pattern 'src/**/*.{ts,tsx}' '{test,bench,examples,scripts}/**/*.ts' '*.ts'"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@oh-my-pi/pi-natives": "18.
|
|
57
|
+
"@oh-my-pi/pi-natives": "18.2.0"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
60
|
"@types/bun": "^1.3.14"
|
package/src/async.ts
CHANGED
|
@@ -1,3 +1,40 @@
|
|
|
1
|
+
import { scheduler } from "node:timers/promises";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Largest delay `setTimeout` (and `timers/promises` `scheduler.wait`)
|
|
5
|
+
* accepts without 32-bit signed overflow: larger values wrap and fire
|
|
6
|
+
* almost immediately instead of sleeping. Chunk day-scale provider waits
|
|
7
|
+
* (e.g. a monthly quota reset parsed from an error hint) so the full
|
|
8
|
+
* duration elapses instead of overflowing the timer.
|
|
9
|
+
*/
|
|
10
|
+
export const MAX_TIMER_DELAY_MS = 2_147_483_647;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Abortable sleep for arbitrarily long delays. Waits longer than
|
|
14
|
+
* {@link MAX_TIMER_DELAY_MS} chunk the sleep into back-to-back timer waits
|
|
15
|
+
* so no single timer overflows; an abort during any chunk rejects like
|
|
16
|
+
* `scheduler.wait`.
|
|
17
|
+
*
|
|
18
|
+
* The remainder is deliberately consumed by chunk, not recomputed from a
|
|
19
|
+
* monotonic deadline: deadline tracking never terminates under the repo's
|
|
20
|
+
* instant `scheduler.wait` mocks (retry-cap suites spy it to resolve
|
|
21
|
+
* immediately, so `deadline - performance.now()` never reaches zero and the
|
|
22
|
+
* loop spins forever). A premature native wake (Bun `uv_async_send`, see
|
|
23
|
+
* `sleepAtLeast` in `packages/agent/src/utils/yield.ts`) can therefore
|
|
24
|
+
* under-wait by the unelapsed chunk time — but that self-corrects downstream:
|
|
25
|
+
* credential blocks carry the true deadline independently of this sleep, so
|
|
26
|
+
* an early retry re-hits 429 and re-sleeps on a fresh server hint.
|
|
27
|
+
*/
|
|
28
|
+
export async function sleepLong(delayMs: number, signal?: AbortSignal): Promise<void> {
|
|
29
|
+
signal?.throwIfAborted();
|
|
30
|
+
let remaining = delayMs;
|
|
31
|
+
while (remaining > 0) {
|
|
32
|
+
await scheduler.wait(Math.min(remaining, MAX_TIMER_DELAY_MS), { signal });
|
|
33
|
+
remaining -= MAX_TIMER_DELAY_MS;
|
|
34
|
+
signal?.throwIfAborted();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
1
38
|
/**
|
|
2
39
|
* Wrap a promise with a timeout and optional abort signal.
|
|
3
40
|
* Rejects with the given error or a new error containing the given message if
|
package/src/browsers.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
import type * as fs from "node:fs";
|
|
1
|
+
/** Managed Chrome-for-Testing installation with bounded downloads and atomic publication. */
|
|
4
2
|
import * as fsp from "node:fs/promises";
|
|
5
3
|
import * as os from "node:os";
|
|
6
4
|
import * as path from "node:path";
|
|
@@ -8,7 +6,6 @@ import { type ArchiveLimits, extractArchive } from "./ar";
|
|
|
8
6
|
import { withFileLock } from "./file-lock";
|
|
9
7
|
|
|
10
8
|
const CHROME_FOR_TESTING_BASE_URL = "https://storage.googleapis.com/chrome-for-testing-public";
|
|
11
|
-
const CHROME_METADATA_BASE_URL = "https://googlechromelabs.github.io/chrome-for-testing";
|
|
12
9
|
// Installation is outside browser/Eval operation deadlines, but a stalled CDN
|
|
13
10
|
// must still release the cached install promise and permit a later attempt.
|
|
14
11
|
const DOWNLOAD_TIMEOUT_MS = 5 * 60_000;
|
|
@@ -25,15 +22,6 @@ const BROWSER_ARCHIVE_LIMITS: Partial<ArchiveLimits> = {
|
|
|
25
22
|
maxInMemorySize: 1024 * 1024 * 1024,
|
|
26
23
|
};
|
|
27
24
|
|
|
28
|
-
/** Supported browser products. */
|
|
29
|
-
export enum Browser {
|
|
30
|
-
CHROME = "chrome",
|
|
31
|
-
CHROMEHEADLESSSHELL = "chrome-headless-shell",
|
|
32
|
-
CHROMIUM = "chromium",
|
|
33
|
-
FIREFOX = "firefox",
|
|
34
|
-
CHROMEDRIVER = "chromedriver",
|
|
35
|
-
}
|
|
36
|
-
|
|
37
25
|
/** Browser download platform identifiers. */
|
|
38
26
|
export enum BrowserPlatform {
|
|
39
27
|
LINUX = "linux",
|
|
@@ -51,34 +39,6 @@ function requireChromeForTestingPlatform(platform: BrowserPlatform): ChromeForTe
|
|
|
51
39
|
return platform;
|
|
52
40
|
}
|
|
53
41
|
|
|
54
|
-
const BROWSERS = [
|
|
55
|
-
Browser.CHROME,
|
|
56
|
-
Browser.CHROMEHEADLESSSHELL,
|
|
57
|
-
Browser.CHROMIUM,
|
|
58
|
-
Browser.FIREFOX,
|
|
59
|
-
Browser.CHROMEDRIVER,
|
|
60
|
-
] as const;
|
|
61
|
-
const BROWSER_PLATFORMS = [
|
|
62
|
-
BrowserPlatform.LINUX,
|
|
63
|
-
BrowserPlatform.LINUX_ARM,
|
|
64
|
-
BrowserPlatform.MAC,
|
|
65
|
-
BrowserPlatform.MAC_ARM,
|
|
66
|
-
BrowserPlatform.WIN32,
|
|
67
|
-
BrowserPlatform.WIN64,
|
|
68
|
-
] as const;
|
|
69
|
-
|
|
70
|
-
/** Chrome-for-Testing release channel tags accepted by {@link resolveBuildId}. */
|
|
71
|
-
export enum BrowserTag {
|
|
72
|
-
CANARY = "canary",
|
|
73
|
-
NIGHTLY = "nightly",
|
|
74
|
-
BETA = "beta",
|
|
75
|
-
DEV = "dev",
|
|
76
|
-
DEVEDITION = "devedition",
|
|
77
|
-
STABLE = "stable",
|
|
78
|
-
ESR = "esr",
|
|
79
|
-
LATEST = "latest",
|
|
80
|
-
}
|
|
81
|
-
|
|
82
42
|
/** Download progress reported while a browser archive is streamed to disk. */
|
|
83
43
|
export interface BrowserDownloadProgress {
|
|
84
44
|
downloadedBytes: number;
|
|
@@ -87,7 +47,6 @@ export interface BrowserDownloadProgress {
|
|
|
87
47
|
|
|
88
48
|
/** Inputs used to locate an installed browser executable. */
|
|
89
49
|
export interface ComputeExecutablePathOptions {
|
|
90
|
-
browser: Browser;
|
|
91
50
|
buildId: string;
|
|
92
51
|
cacheDir: string;
|
|
93
52
|
platform?: BrowserPlatform;
|
|
@@ -99,27 +58,14 @@ export interface InstallOptions extends ComputeExecutablePathOptions {
|
|
|
99
58
|
downloadProgressCallback?: (progress: BrowserDownloadProgress) => void;
|
|
100
59
|
}
|
|
101
60
|
|
|
102
|
-
/** Metadata for
|
|
61
|
+
/** Metadata for a managed Chrome installation in Puppeteer's cache layout. */
|
|
103
62
|
export interface InstalledBrowser {
|
|
104
|
-
browser: Browser;
|
|
105
63
|
buildId: string;
|
|
106
64
|
platform: BrowserPlatform;
|
|
107
65
|
path: string;
|
|
108
66
|
executablePath: string;
|
|
109
67
|
}
|
|
110
68
|
|
|
111
|
-
interface LastKnownGoodVersions {
|
|
112
|
-
channels: Record<string, { version: string }>;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
interface MilestoneVersions {
|
|
116
|
-
milestones: Record<string, { version: string }>;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
interface PatchVersions {
|
|
120
|
-
builds: Record<string, { version: string }>;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
69
|
/** Detect the current host's Puppeteer browser platform. */
|
|
124
70
|
export function detectBrowserPlatform(): BrowserPlatform | undefined {
|
|
125
71
|
const platform = os.platform();
|
|
@@ -130,43 +76,8 @@ export function detectBrowserPlatform(): BrowserPlatform | undefined {
|
|
|
130
76
|
return undefined;
|
|
131
77
|
}
|
|
132
78
|
|
|
133
|
-
/** Resolve a Chrome-for-Testing channel, milestone, or build prefix to a full build ID. */
|
|
134
|
-
export async function resolveBuildId(
|
|
135
|
-
browser: Browser,
|
|
136
|
-
_platform: BrowserPlatform,
|
|
137
|
-
tag: string | BrowserTag,
|
|
138
|
-
): Promise<string> {
|
|
139
|
-
if (browser !== Browser.CHROME && browser !== Browser.CHROMEHEADLESSSHELL && browser !== Browser.CHROMEDRIVER) {
|
|
140
|
-
return tag;
|
|
141
|
-
}
|
|
142
|
-
if (/^\d+\.\d+\.\d+\.\d+$/.test(tag)) return tag;
|
|
143
|
-
|
|
144
|
-
const channel = tag === BrowserTag.LATEST ? "Canary" : chromeChannelName(tag);
|
|
145
|
-
if (channel) {
|
|
146
|
-
const metadata = await fetchMetadata<LastKnownGoodVersions>("last-known-good-versions.json");
|
|
147
|
-
const version = metadata.channels[channel]?.version;
|
|
148
|
-
if (!version) throw new Error(`Chrome channel ${tag} was not found in Chrome-for-Testing metadata`);
|
|
149
|
-
return version;
|
|
150
|
-
}
|
|
151
|
-
if (/^\d+$/.test(tag)) {
|
|
152
|
-
const metadata = await fetchMetadata<MilestoneVersions>("latest-versions-per-milestone.json");
|
|
153
|
-
return metadata.milestones[tag]?.version ?? tag;
|
|
154
|
-
}
|
|
155
|
-
if (/^\d+\.\d+\.\d+$/.test(tag)) {
|
|
156
|
-
const metadata = await fetchMetadata<PatchVersions>("latest-patch-versions-per-build.json");
|
|
157
|
-
return metadata.builds[tag]?.version ?? tag;
|
|
158
|
-
}
|
|
159
|
-
return tag;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
79
|
/** Return the Chrome-for-Testing archive URL for a browser build. */
|
|
163
|
-
export function getDownloadUrl(
|
|
164
|
-
browser: Browser,
|
|
165
|
-
platform: BrowserPlatform,
|
|
166
|
-
buildId: string,
|
|
167
|
-
baseUrl = CHROME_FOR_TESTING_BASE_URL,
|
|
168
|
-
): URL {
|
|
169
|
-
if (browser !== Browser.CHROME) throw new Error(`Unsupported browser download: ${browser}`);
|
|
80
|
+
export function getDownloadUrl(platform: BrowserPlatform, buildId: string, baseUrl = CHROME_FOR_TESTING_BASE_URL): URL {
|
|
170
81
|
const archivePlatform = chromeArchivePlatform(platform);
|
|
171
82
|
const root = baseUrl.replace(/\/$/, "");
|
|
172
83
|
return new URL(`${root}/${buildId}/${archivePlatform}/chrome-${archivePlatform}.zip`);
|
|
@@ -176,9 +87,8 @@ export function getDownloadUrl(
|
|
|
176
87
|
export function computeExecutablePath(options: ComputeExecutablePathOptions): string {
|
|
177
88
|
const detectedPlatform = options.platform ?? detectBrowserPlatform();
|
|
178
89
|
if (!detectedPlatform) throw new Error("Cannot determine a browser platform for this host");
|
|
179
|
-
if (options.browser !== Browser.CHROME) throw new Error(`Unsupported browser executable: ${options.browser}`);
|
|
180
90
|
const platform = requireChromeForTestingPlatform(detectedPlatform);
|
|
181
|
-
const installDir = installationDir(options.cacheDir,
|
|
91
|
+
const installDir = installationDir(options.cacheDir, platform, options.buildId);
|
|
182
92
|
switch (platform) {
|
|
183
93
|
case BrowserPlatform.LINUX:
|
|
184
94
|
return path.join(installDir, "chrome-linux64", "chrome");
|
|
@@ -207,52 +117,14 @@ export function computeExecutablePath(options: ComputeExecutablePathOptions): st
|
|
|
207
117
|
}
|
|
208
118
|
}
|
|
209
119
|
|
|
210
|
-
/** Scan a Puppeteer cache for browser installation directories. */
|
|
211
|
-
export async function getInstalledBrowsers(options: { cacheDir: string }): Promise<InstalledBrowser[]> {
|
|
212
|
-
const installed: InstalledBrowser[] = [];
|
|
213
|
-
for (const browser of BROWSERS) {
|
|
214
|
-
const browserDir = path.join(options.cacheDir, browser);
|
|
215
|
-
let entries: fs.Dirent[];
|
|
216
|
-
try {
|
|
217
|
-
entries = await fsp.readdir(browserDir, { withFileTypes: true });
|
|
218
|
-
} catch (error) {
|
|
219
|
-
if (isMissingPath(error)) continue;
|
|
220
|
-
throw error;
|
|
221
|
-
}
|
|
222
|
-
for (const entry of entries) {
|
|
223
|
-
if (!entry.isDirectory()) continue;
|
|
224
|
-
const parsed = parseInstallationName(entry.name);
|
|
225
|
-
if (!parsed) continue;
|
|
226
|
-
const installPath = path.join(browserDir, entry.name);
|
|
227
|
-
try {
|
|
228
|
-
installed.push({
|
|
229
|
-
browser,
|
|
230
|
-
buildId: parsed.buildId,
|
|
231
|
-
platform: parsed.platform,
|
|
232
|
-
path: installPath,
|
|
233
|
-
executablePath: computeExecutablePath({
|
|
234
|
-
browser,
|
|
235
|
-
buildId: parsed.buildId,
|
|
236
|
-
cacheDir: options.cacheDir,
|
|
237
|
-
platform: parsed.platform,
|
|
238
|
-
}),
|
|
239
|
-
});
|
|
240
|
-
} catch {
|
|
241
|
-
// Other browser products are not part of the surface used by OMP.
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
return installed;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
120
|
/** Download and unpack Chrome into Puppeteer's existing cache layout. */
|
|
249
121
|
export async function install(options: InstallOptions): Promise<InstalledBrowser> {
|
|
250
122
|
const platform = options.platform ?? detectBrowserPlatform();
|
|
251
123
|
if (!platform) throw new Error("Cannot determine a browser platform for this host");
|
|
252
124
|
const executablePath = computeExecutablePath({ ...options, platform });
|
|
253
|
-
const installPath = installationDir(options.cacheDir,
|
|
125
|
+
const installPath = installationDir(options.cacheDir, platform, options.buildId);
|
|
254
126
|
if (await pathExists(executablePath)) {
|
|
255
|
-
return {
|
|
127
|
+
return { buildId: options.buildId, platform, path: installPath, executablePath };
|
|
256
128
|
}
|
|
257
129
|
|
|
258
130
|
await fsp.mkdir(path.dirname(installPath), { recursive: true });
|
|
@@ -267,7 +139,7 @@ export async function install(options: InstallOptions): Promise<InstalledBrowser
|
|
|
267
139
|
const stagingPath = path.join(options.cacheDir, `.browser-${nonce}`);
|
|
268
140
|
try {
|
|
269
141
|
await downloadArchive(
|
|
270
|
-
getDownloadUrl(
|
|
142
|
+
getDownloadUrl(platform, options.buildId, options.baseUrl),
|
|
271
143
|
archivePath,
|
|
272
144
|
options.downloadProgressCallback,
|
|
273
145
|
);
|
|
@@ -284,34 +156,12 @@ export async function install(options: InstallOptions): Promise<InstalledBrowser
|
|
|
284
156
|
]);
|
|
285
157
|
}
|
|
286
158
|
}
|
|
287
|
-
return {
|
|
159
|
+
return { buildId: options.buildId, platform, path: installPath, executablePath };
|
|
288
160
|
},
|
|
289
161
|
{ retries: Math.ceil(DOWNLOAD_TIMEOUT_MS / 100) + 1, retryDelayMs: 100 },
|
|
290
162
|
);
|
|
291
163
|
}
|
|
292
164
|
|
|
293
|
-
function chromeChannelName(tag: string): string | undefined {
|
|
294
|
-
switch (tag) {
|
|
295
|
-
case BrowserTag.STABLE:
|
|
296
|
-
return "Stable";
|
|
297
|
-
case BrowserTag.BETA:
|
|
298
|
-
return "Beta";
|
|
299
|
-
case BrowserTag.DEV:
|
|
300
|
-
return "Dev";
|
|
301
|
-
case BrowserTag.CANARY:
|
|
302
|
-
return "Canary";
|
|
303
|
-
default:
|
|
304
|
-
return undefined;
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
async function fetchMetadata<T>(filename: string): Promise<T> {
|
|
309
|
-
const response = await fetch(`${CHROME_METADATA_BASE_URL}/${filename}`, { signal: AbortSignal.timeout(30_000) });
|
|
310
|
-
if (!response.ok)
|
|
311
|
-
throw new Error(`Failed to fetch Chrome-for-Testing metadata (${response.status} ${response.statusText})`);
|
|
312
|
-
return (await response.json()) as T;
|
|
313
|
-
}
|
|
314
|
-
|
|
315
165
|
function chromeArchivePlatform(platform: BrowserPlatform): string {
|
|
316
166
|
switch (requireChromeForTestingPlatform(platform)) {
|
|
317
167
|
case BrowserPlatform.LINUX:
|
|
@@ -327,17 +177,8 @@ function chromeArchivePlatform(platform: BrowserPlatform): string {
|
|
|
327
177
|
}
|
|
328
178
|
}
|
|
329
179
|
|
|
330
|
-
function installationDir(cacheDir: string,
|
|
331
|
-
return path.join(cacheDir,
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
function parseInstallationName(name: string): { platform: BrowserPlatform; buildId: string } | undefined {
|
|
335
|
-
for (const platform of BROWSER_PLATFORMS) {
|
|
336
|
-
const prefix = `${platform}-`;
|
|
337
|
-
if (name.startsWith(prefix) && name.length > prefix.length)
|
|
338
|
-
return { platform, buildId: name.slice(prefix.length) };
|
|
339
|
-
}
|
|
340
|
-
return undefined;
|
|
180
|
+
function installationDir(cacheDir: string, platform: BrowserPlatform, buildId: string): string {
|
|
181
|
+
return path.join(cacheDir, "chrome", `${platform}-${buildId}`);
|
|
341
182
|
}
|
|
342
183
|
|
|
343
184
|
function isMissingPath(error: unknown): boolean {
|