@linxiraos/pi-utils 1.0.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 +449 -0
- package/README.md +36 -0
- package/dist/types/abortable.d.ts +32 -0
- package/dist/types/acp/connection.d.ts +118 -0
- package/dist/types/acp/protocol.d.ts +526 -0
- package/dist/types/acp/schema.d.ts +41 -0
- package/dist/types/acp/stream.d.ts +8 -0
- package/dist/types/acp/transport.d.ts +81 -0
- package/dist/types/acp.d.ts +6 -0
- package/dist/types/async.d.ts +20 -0
- package/dist/types/binary.d.ts +17 -0
- package/dist/types/browsers.d.ts +68 -0
- package/dist/types/chalk.d.ts +125 -0
- package/dist/types/cli.d.ts +134 -0
- package/dist/types/color.d.ts +102 -0
- package/dist/types/dates.d.ts +7 -0
- package/dist/types/dirs.d.ts +282 -0
- package/dist/types/docx/converter.d.ts +46 -0
- package/dist/types/docx/xml.d.ts +26 -0
- package/dist/types/docx/zip.d.ts +6 -0
- package/dist/types/docx.d.ts +11 -0
- package/dist/types/dom/core.d.ts +431 -0
- package/dist/types/dom/parser.d.ts +7 -0
- package/dist/types/dom/selector.d.ts +5 -0
- package/dist/types/dom.d.ts +5 -0
- package/dist/types/env.d.ts +124 -0
- package/dist/types/fetch-retry.d.ts +96 -0
- package/dist/types/file-lock.d.ts +23 -0
- package/dist/types/format.d.ts +37 -0
- package/dist/types/frontmatter.d.ts +46 -0
- package/dist/types/fs-error.d.ts +31 -0
- package/dist/types/glob.d.ts +28 -0
- package/dist/types/headers.d.ts +34 -0
- package/dist/types/index.d.ts +39 -0
- package/dist/types/json-parse.d.ts +74 -0
- package/dist/types/json.d.ts +14 -0
- package/dist/types/logger/rotating-file.d.ts +18 -0
- package/dist/types/logger.d.ts +96 -0
- package/dist/types/loop-phase.d.ts +10 -0
- package/dist/types/lru.d.ts +46 -0
- package/dist/types/marked/core.d.ts +445 -0
- package/dist/types/marked.d.ts +2 -0
- package/dist/types/mermaid-ascii.d.ts +11 -0
- package/dist/types/mime.d.ts +29 -0
- package/dist/types/module-timer.d.ts +1 -0
- package/dist/types/path-tree.d.ts +76 -0
- package/dist/types/path.d.ts +2 -0
- package/dist/types/peek-file.d.ts +29 -0
- package/dist/types/postmortem.d.ts +104 -0
- package/dist/types/process-name.d.ts +7 -0
- package/dist/types/procmgr.d.ts +74 -0
- package/dist/types/prompt.d.ts +18 -0
- package/dist/types/ptree.d.ts +110 -0
- package/dist/types/readability/readability.d.ts +9 -0
- package/dist/types/readability/readerable.d.ts +10 -0
- package/dist/types/readability/types.d.ts +70 -0
- package/dist/types/readability.d.ts +4 -0
- package/dist/types/ring.d.ts +93 -0
- package/dist/types/runtime-install.d.ts +78 -0
- package/dist/types/sanitize-text.d.ts +29 -0
- package/dist/types/snowflake.d.ts +25 -0
- package/dist/types/stderr-guard.d.ts +22 -0
- package/dist/types/stream.d.ts +67 -0
- package/dist/types/tab-spacing.d.ts +24 -0
- package/dist/types/temp.d.ts +17 -0
- package/dist/types/template.d.ts +62 -0
- package/dist/types/timing-buffer.d.ts +22 -0
- package/dist/types/tls-fetch.d.ts +37 -0
- package/dist/types/turndown/gfm.d.ts +11 -0
- package/dist/types/turndown/html.d.ts +5 -0
- package/dist/types/turndown/service.d.ts +21 -0
- package/dist/types/turndown/types.d.ts +70 -0
- package/dist/types/turndown.d.ts +4 -0
- package/dist/types/type-guards.d.ts +5 -0
- package/dist/types/vendor/mermaid-ascii/ascii/ansi.d.ts +41 -0
- package/dist/types/vendor/mermaid-ascii/ascii/canvas.d.ts +89 -0
- package/dist/types/vendor/mermaid-ascii/ascii/class-diagram.d.ts +7 -0
- package/dist/types/vendor/mermaid-ascii/ascii/converter.d.ts +12 -0
- package/dist/types/vendor/mermaid-ascii/ascii/draw.d.ts +66 -0
- package/dist/types/vendor/mermaid-ascii/ascii/edge-bundling.d.ts +48 -0
- package/dist/types/vendor/mermaid-ascii/ascii/edge-routing.d.ts +43 -0
- package/dist/types/vendor/mermaid-ascii/ascii/er-diagram.d.ts +7 -0
- package/dist/types/vendor/mermaid-ascii/ascii/grid.d.ts +56 -0
- package/dist/types/vendor/mermaid-ascii/ascii/index.d.ts +65 -0
- package/dist/types/vendor/mermaid-ascii/ascii/multiline-utils.d.ts +27 -0
- package/dist/types/vendor/mermaid-ascii/ascii/pathfinder.d.ts +17 -0
- package/dist/types/vendor/mermaid-ascii/ascii/sequence.d.ts +7 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/circle.d.ts +11 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/corners.d.ts +34 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/diamond.d.ts +11 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/hexagon.d.ts +11 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/index.d.ts +26 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/rectangle.d.ts +31 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/rounded.d.ts +11 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/special.d.ts +59 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/stadium.d.ts +17 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/state.d.ts +30 -0
- package/dist/types/vendor/mermaid-ascii/ascii/shapes/types.d.ts +55 -0
- package/dist/types/vendor/mermaid-ascii/ascii/types.d.ts +206 -0
- package/dist/types/vendor/mermaid-ascii/ascii/validate.d.ts +51 -0
- package/dist/types/vendor/mermaid-ascii/ascii/xychart.d.ts +2 -0
- package/dist/types/vendor/mermaid-ascii/class/parser.d.ts +6 -0
- package/dist/types/vendor/mermaid-ascii/class/types.d.ts +102 -0
- package/dist/types/vendor/mermaid-ascii/er/parser.d.ts +6 -0
- package/dist/types/vendor/mermaid-ascii/er/types.d.ts +76 -0
- package/dist/types/vendor/mermaid-ascii/index.d.ts +1 -0
- package/dist/types/vendor/mermaid-ascii/multiline-utils.d.ts +9 -0
- package/dist/types/vendor/mermaid-ascii/parser.d.ts +7 -0
- package/dist/types/vendor/mermaid-ascii/sequence/parser.d.ts +6 -0
- package/dist/types/vendor/mermaid-ascii/sequence/types.d.ts +130 -0
- package/dist/types/vendor/mermaid-ascii/text-metrics.d.ts +21 -0
- package/dist/types/vendor/mermaid-ascii/types.d.ts +114 -0
- package/dist/types/vendor/mermaid-ascii/xychart/colors.d.ts +25 -0
- package/dist/types/vendor/mermaid-ascii/xychart/parser.d.ts +6 -0
- package/dist/types/vendor/mermaid-ascii/xychart/types.d.ts +145 -0
- package/dist/types/version.d.ts +18 -0
- package/dist/types/vterm/buffer.d.ts +99 -0
- package/dist/types/vterm/terminal.d.ts +44 -0
- package/dist/types/vterm.d.ts +8 -0
- package/dist/types/which.d.ts +37 -0
- package/dist/types/worker-host.d.ts +51 -0
- package/dist/types/xml.d.ts +31 -0
- package/package.json +59 -0
- package/src/abortable.ts +109 -0
- package/src/acp/connection.ts +344 -0
- package/src/acp/protocol.ts +466 -0
- package/src/acp/schema.ts +160 -0
- package/src/acp/stream.ts +82 -0
- package/src/acp/transport.ts +213 -0
- package/src/acp.ts +6 -0
- package/src/async.ts +91 -0
- package/src/binary.ts +50 -0
- package/src/browsers.ts +501 -0
- package/src/chalk.ts +312 -0
- package/src/cli.ts +529 -0
- package/src/color.ts +302 -0
- package/src/dates.ts +194 -0
- package/src/dirs.ts +1026 -0
- package/src/docx/converter.ts +681 -0
- package/src/docx/xml.ts +166 -0
- package/src/docx/zip.ts +87 -0
- package/src/docx.ts +20 -0
- package/src/dom/core.ts +1254 -0
- package/src/dom/parser.ts +370 -0
- package/src/dom/selector.ts +290 -0
- package/src/dom.ts +33 -0
- package/src/env.ts +400 -0
- package/src/fetch-retry.ts +379 -0
- package/src/file-lock.ts +69 -0
- package/src/format.ts +113 -0
- package/src/frontmatter.ts +205 -0
- package/src/fs-error.ts +56 -0
- package/src/glob.ts +189 -0
- package/src/headers.ts +167 -0
- package/src/index.ts +59 -0
- package/src/json-parse.ts +821 -0
- package/src/json.ts +23 -0
- package/src/logger/rotating-file.ts +149 -0
- package/src/logger.ts +798 -0
- package/src/loop-phase.ts +49 -0
- package/src/lru.ts +185 -0
- package/src/marked/core.ts +1576 -0
- package/src/marked.ts +2 -0
- package/src/mermaid-ascii.ts +31 -0
- package/src/mime.ts +159 -0
- package/src/module-timer.ts +148 -0
- package/src/path-tree.ts +147 -0
- package/src/path.ts +28 -0
- package/src/peek-file.ts +188 -0
- package/src/postmortem.ts +433 -0
- package/src/process-name.ts +57 -0
- package/src/procmgr.ts +247 -0
- package/src/prompt.ts +545 -0
- package/src/ptree.ts +412 -0
- package/src/readability/readability.ts +533 -0
- package/src/readability/readerable.ts +51 -0
- package/src/readability/types.ts +72 -0
- package/src/readability.ts +11 -0
- package/src/ring.ts +169 -0
- package/src/runtime-install.ts +393 -0
- package/src/sanitize-text.ts +96 -0
- package/src/snowflake.ts +121 -0
- package/src/stderr-guard.ts +155 -0
- package/src/stream.ts +454 -0
- package/src/tab-spacing.ts +336 -0
- package/src/temp.ts +134 -0
- package/src/template.ts +586 -0
- package/src/timing-buffer.ts +47 -0
- package/src/tls-fetch.ts +178 -0
- package/src/turndown/gfm.ts +106 -0
- package/src/turndown/html.ts +257 -0
- package/src/turndown/service.ts +334 -0
- package/src/turndown/types.ts +81 -0
- package/src/turndown.ts +5 -0
- package/src/type-guards.ts +17 -0
- package/src/vendor/mermaid-ascii/NOTICE +33 -0
- package/src/vendor/mermaid-ascii/ascii/ansi.ts +409 -0
- package/src/vendor/mermaid-ascii/ascii/canvas.ts +476 -0
- package/src/vendor/mermaid-ascii/ascii/class-diagram.ts +699 -0
- package/src/vendor/mermaid-ascii/ascii/converter.ts +271 -0
- package/src/vendor/mermaid-ascii/ascii/draw.ts +1382 -0
- package/src/vendor/mermaid-ascii/ascii/edge-bundling.ts +328 -0
- package/src/vendor/mermaid-ascii/ascii/edge-routing.ts +297 -0
- package/src/vendor/mermaid-ascii/ascii/er-diagram.ts +441 -0
- package/src/vendor/mermaid-ascii/ascii/grid.ts +578 -0
- package/src/vendor/mermaid-ascii/ascii/index.ts +187 -0
- package/src/vendor/mermaid-ascii/ascii/multiline-utils.ts +78 -0
- package/src/vendor/mermaid-ascii/ascii/pathfinder.ts +277 -0
- package/src/vendor/mermaid-ascii/ascii/sequence.ts +460 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/circle.ts +27 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/corners.ts +127 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/diamond.ts +27 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/hexagon.ts +27 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/index.ts +101 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/rectangle.ts +175 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/rounded.ts +27 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/special.ts +296 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/stadium.ts +114 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/state.ts +192 -0
- package/src/vendor/mermaid-ascii/ascii/shapes/types.ts +73 -0
- package/src/vendor/mermaid-ascii/ascii/types.ts +273 -0
- package/src/vendor/mermaid-ascii/ascii/validate.ts +120 -0
- package/src/vendor/mermaid-ascii/ascii/xychart.ts +875 -0
- package/src/vendor/mermaid-ascii/class/parser.ts +290 -0
- package/src/vendor/mermaid-ascii/class/types.ts +121 -0
- package/src/vendor/mermaid-ascii/er/parser.ts +181 -0
- package/src/vendor/mermaid-ascii/er/types.ts +91 -0
- package/src/vendor/mermaid-ascii/index.ts +14 -0
- package/src/vendor/mermaid-ascii/multiline-utils.ts +30 -0
- package/src/vendor/mermaid-ascii/parser.ts +645 -0
- package/src/vendor/mermaid-ascii/sequence/parser.ts +207 -0
- package/src/vendor/mermaid-ascii/sequence/types.ts +146 -0
- package/src/vendor/mermaid-ascii/text-metrics.ts +71 -0
- package/src/vendor/mermaid-ascii/types.ts +164 -0
- package/src/vendor/mermaid-ascii/xychart/colors.ts +140 -0
- package/src/vendor/mermaid-ascii/xychart/parser.ts +115 -0
- package/src/vendor/mermaid-ascii/xychart/types.ts +150 -0
- package/src/version.ts +99 -0
- package/src/vterm/buffer.ts +218 -0
- package/src/vterm/terminal.ts +773 -0
- package/src/vterm.ts +8 -0
- package/src/which.ts +234 -0
- package/src/worker-host.ts +100 -0
- package/src/xml.ts +313 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { FileLock as NativeFileLock } from "@linxiraos/pi-natives";
|
|
2
|
+
/** Controls bounded waiting when an advisory file lock is contended. */
|
|
3
|
+
export interface FileLockOptions {
|
|
4
|
+
/** Maximum acquisition attempts, including the initial attempt. */
|
|
5
|
+
retries?: number;
|
|
6
|
+
/** Delay between acquisition attempts. */
|
|
7
|
+
retryDelayMs?: number;
|
|
8
|
+
/** Maximum age of the lock before it is considered stale and can be broken. */
|
|
9
|
+
staleMs?: number;
|
|
10
|
+
}
|
|
11
|
+
declare function getLockPath(filePath: string): string;
|
|
12
|
+
declare function tryAcquireLock(lockPath: string): NativeFileLock | null;
|
|
13
|
+
/** Run `fn` while holding an OS-backed exclusive lock for `filePath`. */
|
|
14
|
+
export declare function withFileLock<T>(filePath: string, fn: () => Promise<T>, options?: FileLockOptions): Promise<T>;
|
|
15
|
+
/**
|
|
16
|
+
* Test-only acquisition handle for forcing ownership handoffs. This is not
|
|
17
|
+
* part of the supported package API.
|
|
18
|
+
*/
|
|
19
|
+
export declare const __internalsForTesting: {
|
|
20
|
+
tryAcquireLock: typeof tryAcquireLock;
|
|
21
|
+
getLockPath: typeof getLockPath;
|
|
22
|
+
};
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Format a duration in milliseconds to a short human-readable string.
|
|
3
|
+
* Examples: "123ms", "1.5s", "30m15s", "2h30m", "3d2h"
|
|
4
|
+
*/
|
|
5
|
+
export declare function formatDuration(ms: number): string;
|
|
6
|
+
/**
|
|
7
|
+
* Format a number with K/M/B suffix for compact display.
|
|
8
|
+
* Uses 1 decimal for small leading digits when non-zero, rounded otherwise.
|
|
9
|
+
* Examples: "999", "1K", "1.5K", "25K", "1M", "1.5M", "25M", "1.5B"
|
|
10
|
+
*/
|
|
11
|
+
export declare function formatNumber(n: number): string;
|
|
12
|
+
/**
|
|
13
|
+
* Format a byte count to a human-readable string.
|
|
14
|
+
* Examples: "512B", "1.5KB", "2.3MB", "1.2GB"
|
|
15
|
+
*/
|
|
16
|
+
export declare function formatBytes(bytes: number): string;
|
|
17
|
+
/**
|
|
18
|
+
* Truncate a string to maxLen characters, appending an ellipsis if truncated.
|
|
19
|
+
* For display-width-aware truncation (terminals), use truncateToWidth from @linxiraos/pi-tui.
|
|
20
|
+
*/
|
|
21
|
+
export declare function truncate(str: string, maxLen: number, ellipsis?: string): string;
|
|
22
|
+
/**
|
|
23
|
+
* Format count with pluralized label (e.g., "3 files", "1 error").
|
|
24
|
+
*/
|
|
25
|
+
export declare function formatCount(label: string, count: number): string;
|
|
26
|
+
/**
|
|
27
|
+
* Format age from seconds to human-readable string.
|
|
28
|
+
*/
|
|
29
|
+
export declare function formatAge(ageSeconds: number | null | undefined): string;
|
|
30
|
+
/**
|
|
31
|
+
* Pluralize a label based on the count.
|
|
32
|
+
*/
|
|
33
|
+
export declare function pluralize(label: string, count: number): string;
|
|
34
|
+
/**
|
|
35
|
+
* Format a ratio as a percentage.
|
|
36
|
+
*/
|
|
37
|
+
export declare function formatPercent(ratio: number): string;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recursively normalize object keys from kebab-case to camelCase — the
|
|
3
|
+
* representation convention for frontmatter consumed inside this codebase.
|
|
4
|
+
* Exported for loaders that parse with `rawKeys: true` to validate exact
|
|
5
|
+
* spec-defined keys, then normalize for storage.
|
|
6
|
+
*/
|
|
7
|
+
export declare function normalizeFrontmatterKeys<T>(obj: T): T;
|
|
8
|
+
export declare class FrontmatterError extends Error {
|
|
9
|
+
readonly source?: unknown;
|
|
10
|
+
constructor(error: Error, source?: unknown);
|
|
11
|
+
toString(): string;
|
|
12
|
+
}
|
|
13
|
+
export interface FrontmatterOptions {
|
|
14
|
+
/** Source of the content (alias: source) */
|
|
15
|
+
location?: unknown;
|
|
16
|
+
/** Source of the content (alias for location) */
|
|
17
|
+
source?: unknown;
|
|
18
|
+
/** Fallback frontmatter values */
|
|
19
|
+
fallback?: Record<string, unknown>;
|
|
20
|
+
/** Normalize the content */
|
|
21
|
+
normalize?: boolean;
|
|
22
|
+
/** Level of error handling */
|
|
23
|
+
level?: "off" | "warn" | "fatal";
|
|
24
|
+
/**
|
|
25
|
+
* Attempt lenient recovery of near-miss input before failing: quote
|
|
26
|
+
* ambiguous plain scalars, replace tabs with spaces, and strip leading HTML
|
|
27
|
+
* comments ahead of the opening delimiter. Default `true`. Spec-conformant
|
|
28
|
+
* loaders set `false` so malformed input is rejected instead of silently
|
|
29
|
+
* repaired (CRLF newline normalization still applies).
|
|
30
|
+
*/
|
|
31
|
+
repair?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Preserve frontmatter keys verbatim instead of normalizing kebab-case to
|
|
34
|
+
* camelCase. Default `false`. Strict spec loaders use this so a standard
|
|
35
|
+
* key (e.g. `allowed-tools`) is never aliased with its camelCase form.
|
|
36
|
+
*/
|
|
37
|
+
rawKeys?: boolean;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Parse YAML frontmatter from markdown content
|
|
41
|
+
* Returns { frontmatter, body } where body has frontmatter stripped
|
|
42
|
+
*/
|
|
43
|
+
export declare function parseFrontmatter(content: string, options?: FrontmatterOptions): {
|
|
44
|
+
frontmatter: Record<string, unknown>;
|
|
45
|
+
body: string;
|
|
46
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type-safe filesystem error handling utilities.
|
|
3
|
+
*
|
|
4
|
+
* Use these to check error codes without string matching on messages:
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { isEnoent, isFsError } from "@linxiraos/pi-utils";
|
|
9
|
+
*
|
|
10
|
+
* try {
|
|
11
|
+
* return await Bun.file(path).text();
|
|
12
|
+
* } catch (err) {
|
|
13
|
+
* if (isEnoent(err)) return null;
|
|
14
|
+
* throw err;
|
|
15
|
+
* }
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export interface FsError extends Error {
|
|
19
|
+
code: string;
|
|
20
|
+
errno?: number;
|
|
21
|
+
syscall?: string;
|
|
22
|
+
path?: string;
|
|
23
|
+
}
|
|
24
|
+
export declare function isFsError(err: unknown): err is FsError;
|
|
25
|
+
export declare function isEnoent(err: unknown): err is FsError;
|
|
26
|
+
export declare function isEacces(err: unknown): err is FsError;
|
|
27
|
+
export declare function isEisdir(err: unknown): err is FsError;
|
|
28
|
+
export declare function isEnotdir(err: unknown): err is FsError;
|
|
29
|
+
export declare function isEexist(err: unknown): err is FsError;
|
|
30
|
+
export declare function isEnotempty(err: unknown): err is FsError;
|
|
31
|
+
export declare function hasFsCode(err: unknown, code: string): err is FsError;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export interface GlobPathsOptions {
|
|
2
|
+
/** Base directory for glob patterns. Defaults to getProjectDir(). */
|
|
3
|
+
cwd?: string;
|
|
4
|
+
/** Glob exclusion patterns. */
|
|
5
|
+
exclude?: string[];
|
|
6
|
+
/** Abort signal to cancel the glob. */
|
|
7
|
+
signal?: AbortSignal;
|
|
8
|
+
/** Timeout in milliseconds for the glob operation. */
|
|
9
|
+
timeoutMs?: number;
|
|
10
|
+
/** Include dotfiles when true. */
|
|
11
|
+
dot?: boolean;
|
|
12
|
+
/** Only return files (skip directories). Default: true. */
|
|
13
|
+
onlyFiles?: boolean;
|
|
14
|
+
/** Respect .gitignore files when true. Walks up directory tree to find all applicable .gitignore files. */
|
|
15
|
+
gitignore?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Load .gitignore patterns from a directory and its parents.
|
|
19
|
+
* Walks up the directory tree to find all applicable .gitignore files.
|
|
20
|
+
* Returns glob-compatible exclude patterns.
|
|
21
|
+
*/
|
|
22
|
+
export declare function loadGitignorePatterns(baseDir: string): Promise<string[]>;
|
|
23
|
+
/**
|
|
24
|
+
* Resolve filesystem paths matching glob patterns with optional exclude filters.
|
|
25
|
+
* Returns paths relative to the provided cwd (or getProjectDir()).
|
|
26
|
+
* Errors and abort/timeouts are surfaced to the caller.
|
|
27
|
+
*/
|
|
28
|
+
export declare function globPaths(patterns: string | string[], options?: GlobPathsOptions): Promise<string[]>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** Behavior-compatible reimplementation of header-generator's used surface. */
|
|
2
|
+
/** A browser family supported by the curated header profiles. */
|
|
3
|
+
export type BrowserName = "chrome" | "firefox" | "safari";
|
|
4
|
+
/** A desktop operating system supported by the curated header profiles. */
|
|
5
|
+
export type OperatingSystem = "windows" | "macos" | "linux";
|
|
6
|
+
/** Constructor and per-call constraints for header generation. */
|
|
7
|
+
export interface HeaderGeneratorOptions {
|
|
8
|
+
/** Browser families eligible for a draw. */
|
|
9
|
+
browsers: BrowserName[];
|
|
10
|
+
/** Browser selection query; the supported `last 3 versions` query uses the curated versions. */
|
|
11
|
+
browserListQuery: string;
|
|
12
|
+
/** Desktop operating systems eligible for a draw. */
|
|
13
|
+
operatingSystems: OperatingSystem[];
|
|
14
|
+
/** Device classes eligible for a draw. */
|
|
15
|
+
devices: "desktop"[];
|
|
16
|
+
/** Ordered locales for the Accept-Language value. */
|
|
17
|
+
locales: string[];
|
|
18
|
+
/** HTTP protocol generation mode. */
|
|
19
|
+
httpVersion: "1" | "2";
|
|
20
|
+
/** Whether impossible constraints throw instead of relaxing to a coherent profile. */
|
|
21
|
+
strict: boolean;
|
|
22
|
+
/** Random source returning a value in the range from zero (inclusive) to one (exclusive). */
|
|
23
|
+
rng: () => number;
|
|
24
|
+
}
|
|
25
|
+
/** A generated HTTP request header map. */
|
|
26
|
+
export type Headers = Record<string, string>;
|
|
27
|
+
/** Generates coherent modern desktop browser navigation headers. */
|
|
28
|
+
export declare class HeaderGenerator {
|
|
29
|
+
#private;
|
|
30
|
+
/** Creates a generator with reusable constraints and an optionally injectable RNG. */
|
|
31
|
+
constructor(options?: Partial<HeaderGeneratorOptions>);
|
|
32
|
+
/** Generates one header set, applying per-call constraints and request overrides. */
|
|
33
|
+
getHeaders(options?: Partial<HeaderGeneratorOptions>, overrides?: Headers): Headers;
|
|
34
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export { once, untilAborted } from "./abortable.js";
|
|
2
|
+
export * from "./async.js";
|
|
3
|
+
export * from "./binary.js";
|
|
4
|
+
export * from "./color.js";
|
|
5
|
+
export * from "./dirs.js";
|
|
6
|
+
export * from "./env.js";
|
|
7
|
+
export * from "./fetch-retry.js";
|
|
8
|
+
export * from "./file-lock.js";
|
|
9
|
+
export * from "./format.js";
|
|
10
|
+
export * from "./frontmatter.js";
|
|
11
|
+
export * from "./fs-error.js";
|
|
12
|
+
export * from "./glob.js";
|
|
13
|
+
export * from "./json.js";
|
|
14
|
+
export * from "./json-parse.js";
|
|
15
|
+
export * as logger from "./logger.js";
|
|
16
|
+
export * from "./loop-phase.js";
|
|
17
|
+
export * from "./mermaid-ascii.js";
|
|
18
|
+
export * from "./mime.js";
|
|
19
|
+
export * from "./path.js";
|
|
20
|
+
export * from "./path-tree.js";
|
|
21
|
+
export * from "./peek-file.js";
|
|
22
|
+
export * as postmortem from "./postmortem.js";
|
|
23
|
+
export * from "./process-name.js";
|
|
24
|
+
export * as procmgr from "./procmgr.js";
|
|
25
|
+
export * as prompt from "./prompt.js";
|
|
26
|
+
export * as ptree from "./ptree.js";
|
|
27
|
+
export { AbortError, ChildProcess, Exception, NonZeroExitError } from "./ptree.js";
|
|
28
|
+
export * from "./runtime-install.js";
|
|
29
|
+
export * from "./sanitize-text.js";
|
|
30
|
+
export * from "./snowflake.js";
|
|
31
|
+
export * from "./stderr-guard.js";
|
|
32
|
+
export * from "./stream.js";
|
|
33
|
+
export * from "./tab-spacing.js";
|
|
34
|
+
export * from "./temp.js";
|
|
35
|
+
export * from "./tls-fetch.js";
|
|
36
|
+
export * from "./type-guards.js";
|
|
37
|
+
export * from "./version.js";
|
|
38
|
+
export * from "./which.js";
|
|
39
|
+
export declare function structuredCloneJSON<T>(value: T): T;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lightweight string-level repair of the escape/control-char hazards that make
|
|
3
|
+
* otherwise-valid JSON fail `JSON.parse`: raw control characters inside strings
|
|
4
|
+
* are escaped, and invalid `\x` escapes have their backslash escaped. Returns the
|
|
5
|
+
* input unchanged when no repair is needed. Pure string→string; does not parse.
|
|
6
|
+
*/
|
|
7
|
+
export declare function repairJson(json: string): string;
|
|
8
|
+
/**
|
|
9
|
+
* Final-parse a JSON value, repairing the common LLM malformations
|
|
10
|
+
* ({@link RelaxedJson}). Tries strict `JSON.parse` first (fast path, exact JSON
|
|
11
|
+
* semantics), then the relaxed parser. Throws when the input is unrepairable,
|
|
12
|
+
* truncated, or carries trailing garbage — so callers can skip a bad tool call
|
|
13
|
+
* rather than execute a half-formed one.
|
|
14
|
+
*/
|
|
15
|
+
export declare function parseJsonWithRepair<T>(json: string): T;
|
|
16
|
+
/**
|
|
17
|
+
* Parse possibly-incomplete JSON during streaming. Always returns a value, never
|
|
18
|
+
* throws: `{}` for empty/whitespace/unrecoverable buffers, and an auto-closed
|
|
19
|
+
* best-effort object for truncated ones.
|
|
20
|
+
*/
|
|
21
|
+
export declare function parseStreamingJson<T = Record<string, unknown>>(partialJson: string | undefined): T;
|
|
22
|
+
/**
|
|
23
|
+
* Default minimum byte growth before `parseStreamingJsonThrottled` will
|
|
24
|
+
* re-parse a streaming tool-call argument buffer. Bounds the mid-stream
|
|
25
|
+
* partial-parse cost from quadratic to linear in N.
|
|
26
|
+
*/
|
|
27
|
+
export declare const STREAMING_JSON_PARSE_MIN_GROWTH = 256;
|
|
28
|
+
/**
|
|
29
|
+
* Throttled variant of {@link parseStreamingJson} for the per-delta hot path.
|
|
30
|
+
*
|
|
31
|
+
* Tool calls arrive as a long sequence of small deltas — calling
|
|
32
|
+
* `parseStreamingJson(buffer)` on every delta re-parses the entire buffer
|
|
33
|
+
* each time, giving O(N²) work in the total buffer length. Throttling skips
|
|
34
|
+
* the re-parse until at least `minGrowthBytes` of new content has arrived
|
|
35
|
+
* since the last successful parse, bounding mid-stream cost to O(N).
|
|
36
|
+
*
|
|
37
|
+
* Each provider tracks the last parsed length on its tool-call block, so the
|
|
38
|
+
* final `toolcall_end` parse (which providers already perform unconditionally)
|
|
39
|
+
* is the authoritative full parse — the throttle only delays mid-stream UI
|
|
40
|
+
* updates by at most `minGrowthBytes` of accumulated partial content.
|
|
41
|
+
*
|
|
42
|
+
* @returns the parsed object plus the new `parsedLen` to persist; or `null`
|
|
43
|
+
* when the buffer has not grown enough to warrant a re-parse.
|
|
44
|
+
*/
|
|
45
|
+
export declare function parseStreamingJsonThrottled<T = Record<string, unknown>>(partialJson: string | undefined, lastParsedLen: number, minGrowthBytes?: number): {
|
|
46
|
+
value: T;
|
|
47
|
+
parsedLen: number;
|
|
48
|
+
} | null;
|
|
49
|
+
/**
|
|
50
|
+
* Classification of a streaming buffer against strict JSON (RFC 8259):
|
|
51
|
+
* - `"complete"`: exactly one whole JSON value (plus surrounding whitespace).
|
|
52
|
+
* - `"prefix"`: a proper prefix of some valid JSON value — more bytes can
|
|
53
|
+
* still complete it.
|
|
54
|
+
* - `"invalid"`: no suffix can ever make it valid strict JSON (e.g. a raw
|
|
55
|
+
* control character inside a string, or a second top-level value).
|
|
56
|
+
*/
|
|
57
|
+
export type JsonPrefixState = "complete" | "prefix" | "invalid";
|
|
58
|
+
/**
|
|
59
|
+
* Classify `text` as a strict-JSON value, prefix, or dead end.
|
|
60
|
+
*
|
|
61
|
+
* Providers use this to disambiguate identifierless streaming tool-call
|
|
62
|
+
* deltas: a chunk starting with `{` is a *new* sibling call only if the
|
|
63
|
+
* current call's argument buffer cannot absorb it — the buffer is already a
|
|
64
|
+
* complete value, already unsalvageable (lossy hosts abandon buffers
|
|
65
|
+
* mid-string, leaving raw control characters strict JSON forbids), or the
|
|
66
|
+
* concatenation would break it. Unlike {@link parseStreamingJson} this is
|
|
67
|
+
* deliberately strict: forgiving repair would mask exactly the corruption
|
|
68
|
+
* signals the caller needs.
|
|
69
|
+
*
|
|
70
|
+
* A top-level number at end-of-input classifies as `"complete"` even though
|
|
71
|
+
* more digits could extend it; tool-argument buffers are always objects, so
|
|
72
|
+
* the ambiguity is immaterial here.
|
|
73
|
+
*/
|
|
74
|
+
export declare function classifyJsonPrefix(text: string): JsonPrefixState;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Try to parse JSON, returning null on failure.
|
|
3
|
+
*/
|
|
4
|
+
export declare function tryParseJson<T = unknown>(content: string): T | null;
|
|
5
|
+
/**
|
|
6
|
+
* Serialize JSON while preserving bigint precision as decimal strings.
|
|
7
|
+
*
|
|
8
|
+
* Tool arguments normally arrive from JSON providers, but extension hooks and
|
|
9
|
+
* host integrations can supply JavaScript bigint values. Native
|
|
10
|
+
* `JSON.stringify` throws for those values, which makes otherwise valid agent
|
|
11
|
+
* history impossible to persist, replay, or compact. A decimal string is the
|
|
12
|
+
* only lossless JSON representation.
|
|
13
|
+
*/
|
|
14
|
+
export declare function stringifyJson(value: unknown, space?: string | number): string | undefined;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** Configuration for a process-local rotating file sink. */
|
|
2
|
+
export interface RotatingFileOptions {
|
|
3
|
+
readonly directory: string;
|
|
4
|
+
readonly filenamePrefix: string;
|
|
5
|
+
readonly filenameSuffix: string;
|
|
6
|
+
readonly auditFile: string;
|
|
7
|
+
readonly maxBytes: number;
|
|
8
|
+
readonly maxFiles: number;
|
|
9
|
+
}
|
|
10
|
+
/** Synchronous append sink with local-day and size rotation plus bounded retention. */
|
|
11
|
+
export declare class RotatingFileSink {
|
|
12
|
+
#private;
|
|
13
|
+
constructor(options: RotatingFileOptions);
|
|
14
|
+
/** Append one already-formatted log record. */
|
|
15
|
+
write(line: string): void;
|
|
16
|
+
/** Stop accepting records. Synchronous writes require no drain phase. */
|
|
17
|
+
close(): void;
|
|
18
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/** Severity names accepted by the centralized logger. */
|
|
2
|
+
export type LogLevel = "error" | "warn" | "info" | "debug";
|
|
3
|
+
/** Structured log event forwarded to out-of-band sinks such as OpenTelemetry. */
|
|
4
|
+
export interface LogEvent {
|
|
5
|
+
readonly level: LogLevel;
|
|
6
|
+
readonly message: string;
|
|
7
|
+
readonly context: Record<string, unknown> | undefined;
|
|
8
|
+
readonly timestamp: Date;
|
|
9
|
+
}
|
|
10
|
+
/** Receives each structured log event after the local transport path runs. */
|
|
11
|
+
export type LogSink = (event: LogEvent) => void;
|
|
12
|
+
/** Register an out-of-band log sink and return a disposer. */
|
|
13
|
+
export declare function registerLogSink(sink: LogSink): () => void;
|
|
14
|
+
/**
|
|
15
|
+
* Replace the active log transports. Pass `console: true, file: false` for
|
|
16
|
+
* long-running services (the auth broker, etc.) that want their structured
|
|
17
|
+
* logs piped into a process supervisor instead of the rotating file.
|
|
18
|
+
*/
|
|
19
|
+
export declare function setTransports(opts: {
|
|
20
|
+
console?: boolean;
|
|
21
|
+
file?: boolean | string;
|
|
22
|
+
}): void;
|
|
23
|
+
/**
|
|
24
|
+
* Log an error message.
|
|
25
|
+
* @param message - The message to log.
|
|
26
|
+
* @param context - The context to log.
|
|
27
|
+
*/
|
|
28
|
+
export declare function error(message: string, context?: Record<string, unknown>): void;
|
|
29
|
+
/**
|
|
30
|
+
* Log a warning message.
|
|
31
|
+
* @param message - The message to log.
|
|
32
|
+
* @param context - The context to log.
|
|
33
|
+
*/
|
|
34
|
+
export declare function warn(message: string, context?: Record<string, unknown>): void;
|
|
35
|
+
/**
|
|
36
|
+
* Log an informational message.
|
|
37
|
+
* @param message - The message to log.
|
|
38
|
+
* @param context - The context to log.
|
|
39
|
+
*/
|
|
40
|
+
export declare function info(message: string, context?: Record<string, unknown>): void;
|
|
41
|
+
/**
|
|
42
|
+
* Log a debug message.
|
|
43
|
+
* @param message - The message to log.
|
|
44
|
+
* @param context - The context to log.
|
|
45
|
+
*/
|
|
46
|
+
export declare function debug(message: string, context?: Record<string, unknown>): void;
|
|
47
|
+
/**
|
|
48
|
+
* Streaming startup markers, enabled by `PI_DEBUG_STARTUP`. Unlike the
|
|
49
|
+
* PI_TIMING tree (printed only after startup completes), these write one
|
|
50
|
+
* synchronous stderr line as each phase begins/ends, so a hard hang still
|
|
51
|
+
* shows the last phase that started. `fs.writeSync(2)` is used deliberately:
|
|
52
|
+
* it cannot be reordered or buffered past a synchronous block of the event
|
|
53
|
+
* loop (dlopen, sync fs on a dead mount, spawnSync).
|
|
54
|
+
*/
|
|
55
|
+
export declare function startupMarker(text: string): void;
|
|
56
|
+
export declare function timingModeIncludes(option: "full" | "x"): boolean;
|
|
57
|
+
export declare function shouldExitAfterTimings(): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Print collected timings as an indented tree.
|
|
60
|
+
* Each span shows wall duration; parents with children also show "(self)" for unattributed time.
|
|
61
|
+
* Sibling spans are sorted by start time. Spans whose intervals overlap with siblings ran in parallel.
|
|
62
|
+
*/
|
|
63
|
+
export declare function printTimings(): void;
|
|
64
|
+
/**
|
|
65
|
+
* Begin recording startup timings under a new root span.
|
|
66
|
+
* Idempotent: a second call while already recording is a no-op, so an explicit
|
|
67
|
+
* starter (main.ts) and any future early starter can coexist.
|
|
68
|
+
*/
|
|
69
|
+
export declare function startTiming(): void;
|
|
70
|
+
/**
|
|
71
|
+
* Record an externally-measured span as a leaf child of the active span (or root
|
|
72
|
+
* when no span is active). Used by {@link spliceModuleLoadBuffer} to fold
|
|
73
|
+
* preload-captured module windows into the tree.
|
|
74
|
+
*/
|
|
75
|
+
export declare function recordModuleLoadSpan(path: string, start: number, durationMs: number, bodyMs?: number, imports?: string[]): void;
|
|
76
|
+
/**
|
|
77
|
+
* End timing window and clear buffers.
|
|
78
|
+
*/
|
|
79
|
+
export declare function endTiming(): void;
|
|
80
|
+
/**
|
|
81
|
+
* Ops of the currently-open span chain (root → deepest), following the most
|
|
82
|
+
* recently started unfinished child at each level. Lets a startup watchdog
|
|
83
|
+
* name the phase a stalled startup is stuck in.
|
|
84
|
+
*/
|
|
85
|
+
export declare function openSpanPath(): string[];
|
|
86
|
+
/**
|
|
87
|
+
* Time a span. Three forms:
|
|
88
|
+
* time(op) — point event (zero-duration breadcrumb)
|
|
89
|
+
* time(op, fn, ...args) — wrap fn in a span; returns fn's return value (sync or Promise)
|
|
90
|
+
*
|
|
91
|
+
* Spans nest hierarchically via AsyncLocalStorage: a child started inside another span's fn
|
|
92
|
+
* (even across awaits) becomes that span's child. Parallel children are recorded as siblings
|
|
93
|
+
* with overlapping intervals.
|
|
94
|
+
*/
|
|
95
|
+
export declare function time(op: string): void;
|
|
96
|
+
export declare function time<T, A extends unknown[]>(op: string, fn: (...args: A) => T, ...args: A): T;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare function pushLoopPhase(label: string): void;
|
|
2
|
+
export declare function popLoopPhase(): void;
|
|
3
|
+
export declare function currentLoopPhase(): string | undefined;
|
|
4
|
+
/**
|
|
5
|
+
* Phase to blame for a just-detected loop block: the live top phase if one is
|
|
6
|
+
* still held, else the most recent phase pushed since the last call. Clears the
|
|
7
|
+
* recent slot so a block in a later, phase-less interval is not misattributed
|
|
8
|
+
* to a phase that already finished.
|
|
9
|
+
*/
|
|
10
|
+
export declare function takeRecentLoopPhase(): string | undefined;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/** Behavior-compatible reimplementation of lru-cache's used surface. */
|
|
2
|
+
/** Why an entry left the cache. */
|
|
3
|
+
export type DisposeReason = "evict" | "set" | "delete" | "expire";
|
|
4
|
+
/** Options supported by {@link LRUCache}. */
|
|
5
|
+
export interface LRUCacheOptions<K, V> {
|
|
6
|
+
/** Maximum number of retained entries. */
|
|
7
|
+
max?: number;
|
|
8
|
+
/** Maximum aggregate calculated size. */
|
|
9
|
+
maxSize?: number;
|
|
10
|
+
/** Maximum calculated size of one entry. */
|
|
11
|
+
maxEntrySize?: number;
|
|
12
|
+
/** Calculates an entry's size. */
|
|
13
|
+
sizeCalculation?: (value: V, key: K) => number;
|
|
14
|
+
/** Entry lifetime in milliseconds; zero disables expiry. */
|
|
15
|
+
ttl?: number;
|
|
16
|
+
/** Refreshes an entry's lifetime when it is read. */
|
|
17
|
+
updateAgeOnGet?: boolean;
|
|
18
|
+
/** Called synchronously before an entry is removed. */
|
|
19
|
+
dispose?: (value: V, key: K, reason: DisposeReason) => void;
|
|
20
|
+
}
|
|
21
|
+
/** A bounded least-recently-used cache with optional size and lifetime limits. */
|
|
22
|
+
export declare class LRUCache<K, V> {
|
|
23
|
+
#private;
|
|
24
|
+
/** Creates an empty cache. */
|
|
25
|
+
constructor(options: LRUCacheOptions<K, V>);
|
|
26
|
+
/** Number of entries, including stale entries not yet removed by `get`. */
|
|
27
|
+
get size(): number;
|
|
28
|
+
/** Aggregate calculated size of retained entries. */
|
|
29
|
+
get calculatedSize(): number;
|
|
30
|
+
/** Stores a value and makes it most recently used. */
|
|
31
|
+
set(key: K, value: V | undefined): this;
|
|
32
|
+
/** Returns a value and makes a fresh entry most recently used. */
|
|
33
|
+
get(key: K): V | undefined;
|
|
34
|
+
/** Reports whether a fresh value is present without changing recency. */
|
|
35
|
+
has(key: K): boolean;
|
|
36
|
+
/** Returns a fresh value without changing recency or removing stale data. */
|
|
37
|
+
peek(key: K): V | undefined;
|
|
38
|
+
/** Removes a value, returning whether one was present. */
|
|
39
|
+
delete(key: K): boolean;
|
|
40
|
+
/** Removes every value from least to most recently used. */
|
|
41
|
+
clear(): void;
|
|
42
|
+
/** Iterates fresh keys from most to least recently used. */
|
|
43
|
+
keys(): Generator<K, void, unknown>;
|
|
44
|
+
/** Iterates fresh values from most to least recently used. */
|
|
45
|
+
values(): Generator<V, void, unknown>;
|
|
46
|
+
}
|