@oh-my-pi/pi-utils 15.1.1 → 15.1.3
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/dist/types/abortable.d.ts +27 -0
- package/dist/types/async.d.ts +6 -0
- package/dist/types/cli.d.ts +117 -0
- package/dist/types/color.d.ts +82 -0
- package/dist/types/dirs.d.ts +151 -0
- package/dist/types/env.d.ts +31 -0
- package/dist/types/fetch-retry.d.ts +80 -0
- package/dist/types/format.d.ts +37 -0
- package/dist/types/frontmatter.d.ts +25 -0
- package/dist/types/fs-error.d.ts +31 -0
- package/dist/types/glob.d.ts +28 -0
- package/dist/types/hook-fetch.d.ts +16 -0
- package/dist/types/index.d.ts +29 -0
- package/dist/types/json.d.ts +4 -0
- package/dist/types/logger.d.ts +66 -0
- package/dist/types/mermaid-ascii.d.ts +11 -0
- package/dist/types/mime.d.ts +29 -0
- package/dist/types/peek-file.d.ts +9 -0
- package/dist/types/postmortem.d.ts +29 -0
- package/dist/types/procmgr.d.ts +35 -0
- package/dist/types/prompt.d.ts +18 -0
- package/dist/types/ptree.d.ts +108 -0
- package/dist/types/ring.d.ts +93 -0
- package/dist/types/sanitize-text.d.ts +14 -0
- package/dist/types/snowflake.d.ts +25 -0
- package/dist/types/stream.d.ts +68 -0
- package/dist/types/tab-spacing.d.ts +9 -0
- package/dist/types/temp.d.ts +14 -0
- package/dist/types/type-guards.d.ts +3 -0
- package/dist/types/which.d.ts +37 -0
- package/package.json +8 -7
- package/src/dirs.ts +73 -0
- package/src/frontmatter.ts +1 -1
- package/src/index.ts +1 -0
- package/src/logger.ts +56 -20
- package/src/sanitize-text.ts +38 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export declare class AbortError extends Error {
|
|
2
|
+
constructor(signal: AbortSignal);
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* Creates an abortable stream from a given stream and signal.
|
|
6
|
+
*
|
|
7
|
+
* @param stream - The stream to make abortable
|
|
8
|
+
* @param signal - The signal to abort the stream
|
|
9
|
+
* @returns The abortable stream
|
|
10
|
+
*/
|
|
11
|
+
export declare function createAbortableStream<T>(stream: ReadableStream<T>, signal?: AbortSignal): ReadableStream<T>;
|
|
12
|
+
/**
|
|
13
|
+
* Runs a promise-returning function (`pr`). If the given AbortSignal is aborted before or during
|
|
14
|
+
* execution, the promise is rejected with a standard error.
|
|
15
|
+
*
|
|
16
|
+
* @param signal - Optional AbortSignal to cancel the operation
|
|
17
|
+
* @param pr - Function returning a promise to run
|
|
18
|
+
* @returns Promise resolving as `pr` would, or rejecting on abort
|
|
19
|
+
*/
|
|
20
|
+
export declare function untilAborted<T>(signal: AbortSignal | undefined | null, pr: Promise<T> | (() => Promise<T>)): Promise<T>;
|
|
21
|
+
/**
|
|
22
|
+
* Memoizes a function with no arguments, calling it once and caching the result.
|
|
23
|
+
*
|
|
24
|
+
* @param fn - Function to be called once
|
|
25
|
+
* @returns A function that returns the cached result of `fn`
|
|
26
|
+
*/
|
|
27
|
+
export declare function once<T>(fn: () => T): () => T;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wrap a promise with a timeout and optional abort signal.
|
|
3
|
+
* Rejects with the given message if the timeout fires first.
|
|
4
|
+
* Cleans up all listeners on settlement.
|
|
5
|
+
*/
|
|
6
|
+
export declare function withTimeout<T>(promise: Promise<T>, ms: number, message: string, signal?: AbortSignal): Promise<T>;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
export interface FlagDescriptor<K extends "string" | "boolean" | "integer" = "string" | "boolean" | "integer"> {
|
|
2
|
+
kind: K;
|
|
3
|
+
description?: string;
|
|
4
|
+
char?: string;
|
|
5
|
+
default?: unknown;
|
|
6
|
+
multiple?: boolean;
|
|
7
|
+
options?: readonly string[];
|
|
8
|
+
required?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface ArgDescriptor {
|
|
11
|
+
kind: "string";
|
|
12
|
+
description?: string;
|
|
13
|
+
required?: boolean;
|
|
14
|
+
multiple?: boolean;
|
|
15
|
+
options?: readonly string[];
|
|
16
|
+
}
|
|
17
|
+
interface FlagInput {
|
|
18
|
+
description?: string;
|
|
19
|
+
char?: string;
|
|
20
|
+
default?: unknown;
|
|
21
|
+
multiple?: boolean;
|
|
22
|
+
options?: readonly string[];
|
|
23
|
+
required?: boolean;
|
|
24
|
+
}
|
|
25
|
+
interface ArgInput {
|
|
26
|
+
description?: string;
|
|
27
|
+
required?: boolean;
|
|
28
|
+
multiple?: boolean;
|
|
29
|
+
options?: readonly string[];
|
|
30
|
+
}
|
|
31
|
+
/** Builders that match the `Flags.*()` / `Args.*()` API from oclif. */
|
|
32
|
+
export declare const Flags: {
|
|
33
|
+
string<T extends FlagInput>(opts?: T): FlagDescriptor<"string"> & T;
|
|
34
|
+
boolean<T_1 extends FlagInput>(opts?: T_1): FlagDescriptor<"boolean"> & T_1;
|
|
35
|
+
integer<T_2 extends FlagInput & {
|
|
36
|
+
default?: number;
|
|
37
|
+
}>(opts?: T_2): FlagDescriptor<"integer"> & T_2;
|
|
38
|
+
};
|
|
39
|
+
export declare const Args: {
|
|
40
|
+
string<T extends ArgInput>(opts?: T): ArgDescriptor & T;
|
|
41
|
+
};
|
|
42
|
+
type FlagValue<D extends FlagDescriptor> = D["kind"] extends "boolean" ? D extends {
|
|
43
|
+
default: boolean;
|
|
44
|
+
} ? boolean : boolean | undefined : D["kind"] extends "integer" ? D extends {
|
|
45
|
+
default: number;
|
|
46
|
+
} ? number : number | undefined : D extends {
|
|
47
|
+
multiple: true;
|
|
48
|
+
} ? string[] | undefined : string | undefined;
|
|
49
|
+
type ArgValue<D extends ArgDescriptor> = D extends {
|
|
50
|
+
multiple: true;
|
|
51
|
+
} ? string[] | undefined : string | undefined;
|
|
52
|
+
type FlagValues<T extends Record<string, FlagDescriptor>> = {
|
|
53
|
+
[K in keyof T]: FlagValue<T[K]>;
|
|
54
|
+
};
|
|
55
|
+
type ArgValues<T extends Record<string, ArgDescriptor>> = {
|
|
56
|
+
[K in keyof T]: ArgValue<T[K]>;
|
|
57
|
+
};
|
|
58
|
+
export interface ParseOutput<F extends Record<string, FlagDescriptor> = Record<string, FlagDescriptor>, A extends Record<string, ArgDescriptor> = Record<string, ArgDescriptor>> {
|
|
59
|
+
flags: FlagValues<F>;
|
|
60
|
+
args: ArgValues<A>;
|
|
61
|
+
argv: string[];
|
|
62
|
+
}
|
|
63
|
+
export interface CommandCtor {
|
|
64
|
+
new (argv: string[], config: CliConfig): Command;
|
|
65
|
+
description?: string;
|
|
66
|
+
hidden?: boolean;
|
|
67
|
+
strict?: boolean;
|
|
68
|
+
aliases?: string[];
|
|
69
|
+
examples?: string[];
|
|
70
|
+
flags?: Record<string, FlagDescriptor>;
|
|
71
|
+
args?: Record<string, ArgDescriptor>;
|
|
72
|
+
}
|
|
73
|
+
/** Configuration passed to every command instance and help renderers. */
|
|
74
|
+
export interface CliConfig {
|
|
75
|
+
bin: string;
|
|
76
|
+
version: string;
|
|
77
|
+
/** All registered commands keyed by their canonical name. */
|
|
78
|
+
commands: Map<string, CommandCtor>;
|
|
79
|
+
}
|
|
80
|
+
/** Minimal Command base matching the oclif surface we use. */
|
|
81
|
+
export declare abstract class Command {
|
|
82
|
+
argv: string[];
|
|
83
|
+
config: CliConfig;
|
|
84
|
+
constructor(argv: string[], config: CliConfig);
|
|
85
|
+
abstract run(): Promise<void>;
|
|
86
|
+
/**
|
|
87
|
+
* Parse argv against the static `flags` and `args` declared on the
|
|
88
|
+
* concrete command class. Returns a typed `{ flags, args, argv }` object.
|
|
89
|
+
*/
|
|
90
|
+
parse<C extends CommandCtor>(_Cmd: C): Promise<ParseOutput<NonNullable<C["flags"]> extends Record<string, FlagDescriptor> ? NonNullable<C["flags"]> : Record<string, FlagDescriptor>, NonNullable<C["args"]> extends Record<string, ArgDescriptor> ? NonNullable<C["args"]> : Record<string, ArgDescriptor>>>;
|
|
91
|
+
}
|
|
92
|
+
/** Render full root help: header, default command details, subcommand list. */
|
|
93
|
+
export declare function renderRootHelp(config: CliConfig): void;
|
|
94
|
+
/** Render help for a single command. */
|
|
95
|
+
export declare function renderCommandHelp(bin: string, id: string, Cmd: CommandCtor): void;
|
|
96
|
+
/** A lazily-loaded command: canonical name, loader, and optional aliases. */
|
|
97
|
+
export interface CommandEntry {
|
|
98
|
+
name: string;
|
|
99
|
+
load: () => Promise<CommandCtor>;
|
|
100
|
+
aliases?: string[];
|
|
101
|
+
}
|
|
102
|
+
export interface RunOptions {
|
|
103
|
+
bin: string;
|
|
104
|
+
version: string;
|
|
105
|
+
argv: string[];
|
|
106
|
+
commands: CommandEntry[];
|
|
107
|
+
/** Custom help renderer. Receives fully-populated config. */
|
|
108
|
+
help?: (config: CliConfig) => Promise<void> | void;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Main entry point — replaces `run()` from @oclif/core.
|
|
112
|
+
*
|
|
113
|
+
* Each command is explicitly registered with a lazy loader.
|
|
114
|
+
* No filesystem scanning, no plugin system, no package.json reading.
|
|
115
|
+
*/
|
|
116
|
+
export declare function run(opts: RunOptions): Promise<void>;
|
|
117
|
+
export {};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Color manipulation utilities for hex colors.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { hexToHsv, hsvToHex } from "@oh-my-pi/pi-utils";
|
|
7
|
+
*
|
|
8
|
+
* // Work with HSV directly
|
|
9
|
+
*
|
|
10
|
+
* // Or work with HSV directly
|
|
11
|
+
* const hsv = hexToHsv("#4ade80");
|
|
12
|
+
* hsv.h = (hsv.h + 90) % 360;
|
|
13
|
+
* const newHex = hsvToHex(hsv);
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export interface HSV {
|
|
17
|
+
/** Hue in degrees (0-360) */
|
|
18
|
+
h: number;
|
|
19
|
+
/** Saturation (0-1) */
|
|
20
|
+
s: number;
|
|
21
|
+
/** Value/brightness (0-1) */
|
|
22
|
+
v: number;
|
|
23
|
+
}
|
|
24
|
+
export interface RGB {
|
|
25
|
+
/** Red (0-255) */
|
|
26
|
+
r: number;
|
|
27
|
+
/** Green (0-255) */
|
|
28
|
+
g: number;
|
|
29
|
+
/** Blue (0-255) */
|
|
30
|
+
b: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Parse a hex color string to RGB.
|
|
34
|
+
* Supports #RGB, #RRGGBB formats.
|
|
35
|
+
*/
|
|
36
|
+
export declare function hexToRgb(hex: string): RGB;
|
|
37
|
+
/**
|
|
38
|
+
* Convert RGB to hex color string.
|
|
39
|
+
*/
|
|
40
|
+
export declare function rgbToHex(rgb: RGB): string;
|
|
41
|
+
/**
|
|
42
|
+
* Convert RGB to HSV.
|
|
43
|
+
*/
|
|
44
|
+
export declare function rgbToHsv(rgb: RGB): HSV;
|
|
45
|
+
/**
|
|
46
|
+
* Convert HSV to RGB.
|
|
47
|
+
*/
|
|
48
|
+
export declare function hsvToRgb(hsv: HSV): RGB;
|
|
49
|
+
/**
|
|
50
|
+
* Convert hex color to HSV.
|
|
51
|
+
*/
|
|
52
|
+
export declare function hexToHsv(hex: string): HSV;
|
|
53
|
+
/**
|
|
54
|
+
* Convert HSV to hex color.
|
|
55
|
+
*/
|
|
56
|
+
export declare function hsvToHex(hsv: HSV): string;
|
|
57
|
+
/**
|
|
58
|
+
* Shift the hue of a hex color by a given number of degrees.
|
|
59
|
+
*/
|
|
60
|
+
export declare function shiftHue(hex: string, degrees: number): string;
|
|
61
|
+
export interface HSVAdjustment {
|
|
62
|
+
/** Hue shift in degrees (additive) */
|
|
63
|
+
h?: number;
|
|
64
|
+
/** Saturation multiplier */
|
|
65
|
+
s?: number;
|
|
66
|
+
/** Value/brightness multiplier */
|
|
67
|
+
v?: number;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Adjust HSV components of a hex color.
|
|
71
|
+
*
|
|
72
|
+
* @param hex - Hex color string (#RGB or #RRGGBB)
|
|
73
|
+
* @param adj - Adjustments: h is additive degrees, s and v are multipliers
|
|
74
|
+
* @returns New hex color string
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```ts
|
|
78
|
+
* // Shift hue +60°, reduce saturation to 71%
|
|
79
|
+
* adjustHsv("#00ff88", { h: 60, s: 0.71 }) // "#4a9eff"
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
export declare function adjustHsv(hex: string, adj: HSVAdjustment): string;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Centralized path helpers for omp config directories.
|
|
3
|
+
*
|
|
4
|
+
* Uses PI_CONFIG_DIR (default ".omp") for the config root and
|
|
5
|
+
* PI_CODING_AGENT_DIR to override the agent directory.
|
|
6
|
+
*
|
|
7
|
+
* On Linux, if XDG_DATA_HOME / XDG_STATE_HOME / XDG_CACHE_HOME environment
|
|
8
|
+
* variables are set, paths are redirected to XDG-compliant locations under
|
|
9
|
+
* $XDG_*_HOME/omp/. This requires running `omp config migrate` first to
|
|
10
|
+
* move data to the new locations. No filesystem existence checks are performed
|
|
11
|
+
* — if the env var is set, omp trusts that the migration has been done.
|
|
12
|
+
*/
|
|
13
|
+
/** App name (e.g. "omp") */
|
|
14
|
+
export declare const APP_NAME: string;
|
|
15
|
+
/** Config directory name (e.g. ".omp") */
|
|
16
|
+
export declare const CONFIG_DIR_NAME: string;
|
|
17
|
+
/** Version (e.g. "1.0.0") */
|
|
18
|
+
export declare const VERSION: string;
|
|
19
|
+
/** Minimum Bun version */
|
|
20
|
+
export declare const MIN_BUN_VERSION: string;
|
|
21
|
+
export declare function resolveEquivalentPath(inputPath: string): string;
|
|
22
|
+
export declare function normalizePathForComparison(inputPath: string): string;
|
|
23
|
+
export declare function pathIsWithin(root: string, candidate: string): boolean;
|
|
24
|
+
export declare function relativePathWithinRoot(root: string, candidate: string): string | null;
|
|
25
|
+
/** Get the project directory. */
|
|
26
|
+
export declare function getProjectDir(): string;
|
|
27
|
+
/** Set the project directory. */
|
|
28
|
+
export declare function setProjectDir(dir: string): void;
|
|
29
|
+
/** Get the config directory name relative to home (e.g. ".omp" or PI_CONFIG_DIR override). */
|
|
30
|
+
export declare function getConfigDirName(): string;
|
|
31
|
+
/** Get the config agent directory name relative to home (e.g. ".omp/agent" or PI_CONFIG_DIR + "/agent"). */
|
|
32
|
+
export declare function getConfigAgentDirName(): string;
|
|
33
|
+
/** Get the config root directory (~/.omp). */
|
|
34
|
+
export declare function getConfigRootDir(): string;
|
|
35
|
+
/** Set the coding agent directory. Creates a fresh resolver, invalidating all cached paths. */
|
|
36
|
+
export declare function setAgentDir(dir: string): void;
|
|
37
|
+
/** Get the agent config directory (~/.omp/agent). */
|
|
38
|
+
export declare function getAgentDir(): string;
|
|
39
|
+
/** Get the project-local config directory (.omp). */
|
|
40
|
+
export declare function getProjectAgentDir(cwd?: string): string;
|
|
41
|
+
/** Get the reports directory (~/.omp/reports). */
|
|
42
|
+
export declare function getReportsDir(): string;
|
|
43
|
+
/** Get the logs directory (~/.omp/logs). */
|
|
44
|
+
export declare function getLogsDir(): string;
|
|
45
|
+
/** Get the path to a dated log file (~/.omp/logs/omp.YYYY-MM-DD.log). */
|
|
46
|
+
export declare function getLogPath(date?: Date): string;
|
|
47
|
+
/**
|
|
48
|
+
* Get the plugins directory (~/.omp/plugins or its XDG equivalent).
|
|
49
|
+
*
|
|
50
|
+
* No-arg form (production callers) goes through the XDG-aware DirResolver so
|
|
51
|
+
* reads and writes always agree. The optional `home` parameter is for test
|
|
52
|
+
* isolation: when it differs from `os.homedir()` it short-circuits the resolver
|
|
53
|
+
* and returns `<home>/<configDir>/plugins` so tests with a temp HOME get a
|
|
54
|
+
* deterministic path. Passing `os.homedir()` explicitly is identical to the
|
|
55
|
+
* no-arg form — XDG semantics are preserved.
|
|
56
|
+
*/
|
|
57
|
+
export declare function getPluginsDir(home?: string): string;
|
|
58
|
+
/** Where npm installs packages (~/.omp/plugins/node_modules). */
|
|
59
|
+
export declare function getPluginsNodeModules(): string;
|
|
60
|
+
/** Plugin manifest (~/.omp/plugins/package.json). */
|
|
61
|
+
export declare function getPluginsPackageJson(): string;
|
|
62
|
+
/** Plugin lock file (~/.omp/plugins/omp-plugins.lock.json). */
|
|
63
|
+
export declare function getPluginsLockfile(): string;
|
|
64
|
+
/** Get the remote mount directory (~/.omp/remote). */
|
|
65
|
+
export declare function getRemoteDir(): string;
|
|
66
|
+
/** Get the PR worktrees directory (~/.omp/wt). */
|
|
67
|
+
export declare function getWorktreesDir(): string;
|
|
68
|
+
/** Get the SSH control socket directory (~/.omp/ssh-control). */
|
|
69
|
+
export declare function getSshControlDir(): string;
|
|
70
|
+
/** Get the remote host info directory (~/.omp/remote-host). */
|
|
71
|
+
export declare function getRemoteHostDir(): string;
|
|
72
|
+
/** Get the managed Python venv directory (~/.omp/python-env). */
|
|
73
|
+
export declare function getPythonEnvDir(): string;
|
|
74
|
+
/** Get the shared Python gateway state directory (~/.omp/agent/python-gateway; XDG default: $XDG_STATE_HOME/omp/python-gateway). */
|
|
75
|
+
export declare function getPythonGatewayDir(): string;
|
|
76
|
+
/** Get the puppeteer sandbox directory (~/.omp/puppeteer). */
|
|
77
|
+
export declare function getPuppeteerDir(): string;
|
|
78
|
+
/** Get the worktree base directory (~/.omp/wt). */
|
|
79
|
+
export declare function getWorktreeBaseDir(): string;
|
|
80
|
+
/** Get the path to a worktree directory (~/.omp/wt/<project>/<id>). */
|
|
81
|
+
export declare function getWorktreeDir(encodedProject: string, id: string): string;
|
|
82
|
+
/** Get the GPU cache path (~/.omp/gpu_cache.json). */
|
|
83
|
+
export declare function getGpuCachePath(): string;
|
|
84
|
+
/**
|
|
85
|
+
* Get the GitHub view cache database path (~/.omp/cache/github-cache.db).
|
|
86
|
+
* Honors the `OMP_GITHUB_CACHE_DB` env var when set so tests can isolate the
|
|
87
|
+
* cache file without touching the rest of the config root.
|
|
88
|
+
*/
|
|
89
|
+
export declare function getGithubCacheDbPath(): string;
|
|
90
|
+
/** Get the natives directory (~/.omp/natives). */
|
|
91
|
+
export declare function getNativesDir(): string;
|
|
92
|
+
/** Get the stats database path (~/.omp/stats.db). */
|
|
93
|
+
export declare function getStatsDbPath(): string;
|
|
94
|
+
/** Get the autoresearch state directory (~/.omp/autoresearch). */
|
|
95
|
+
export declare function getAutoresearchDir(): string;
|
|
96
|
+
/** Get the per-project autoresearch state directory (~/.omp/autoresearch/<encoded-project>). */
|
|
97
|
+
export declare function getAutoresearchProjectDir(encodedProject: string): string;
|
|
98
|
+
/** Get the per-project autoresearch SQLite database path (~/.omp/autoresearch/<encoded-project>.db). */
|
|
99
|
+
export declare function getAutoresearchDbPath(encodedProject: string): string;
|
|
100
|
+
/** Get the per-run artifact directory (~/.omp/autoresearch/<encoded-project>/runs/<runId>). */
|
|
101
|
+
export declare function getAutoresearchRunDir(encodedProject: string, runId: number): string;
|
|
102
|
+
/** Get the path to agent.db (SQLite database for settings and auth storage). */
|
|
103
|
+
export declare function getAgentDbPath(agentDir?: string): string;
|
|
104
|
+
/** Get the path to history.db (SQLite database for session history). */
|
|
105
|
+
export declare function getHistoryDbPath(agentDir?: string): string;
|
|
106
|
+
/** Get the path to models.db (model cache database). */
|
|
107
|
+
export declare function getModelDbPath(agentDir?: string): string;
|
|
108
|
+
/** Get the sessions directory (~/.omp/agent/sessions). */
|
|
109
|
+
export declare function getSessionsDir(agentDir?: string): string;
|
|
110
|
+
/** Get the content-addressed blob store directory (~/.omp/agent/blobs). */
|
|
111
|
+
export declare function getBlobsDir(agentDir?: string): string;
|
|
112
|
+
/** Get the custom themes directory (~/.omp/agent/themes). */
|
|
113
|
+
export declare function getCustomThemesDir(agentDir?: string): string;
|
|
114
|
+
/** Get the tools directory (~/.omp/agent/tools). */
|
|
115
|
+
export declare function getToolsDir(agentDir?: string): string;
|
|
116
|
+
/** Get the slash commands directory (~/.omp/agent/commands). */
|
|
117
|
+
export declare function getCommandsDir(agentDir?: string): string;
|
|
118
|
+
/** Get the prompts directory (~/.omp/agent/prompts). */
|
|
119
|
+
export declare function getPromptsDir(agentDir?: string): string;
|
|
120
|
+
/** Get the user-level Python modules directory (~/.omp/agent/modules). */
|
|
121
|
+
export declare function getAgentModulesDir(agentDir?: string): string;
|
|
122
|
+
/** Get the memories directory (~/.omp/agent/memories). */
|
|
123
|
+
export declare function getMemoriesDir(agentDir?: string): string;
|
|
124
|
+
/** Get the terminal sessions directory (~/.omp/agent/terminal-sessions). */
|
|
125
|
+
export declare function getTerminalSessionsDir(agentDir?: string): string;
|
|
126
|
+
/** Get the crash log path (~/.omp/agent/omp-crash.log). */
|
|
127
|
+
export declare function getCrashLogPath(agentDir?: string): string;
|
|
128
|
+
/** Get the debug log path (~/.omp/agent/omp-debug.log). */
|
|
129
|
+
export declare function getDebugLogPath(agentDir?: string): string;
|
|
130
|
+
/** Get the project-level Python modules directory (.omp/modules). */
|
|
131
|
+
export declare function getProjectModulesDir(cwd?: string): string;
|
|
132
|
+
/** Get the project-level prompts directory (.omp/prompts). */
|
|
133
|
+
export declare function getProjectPromptsDir(cwd?: string): string;
|
|
134
|
+
/** Get the project-level plugin overrides path (.omp/plugin-overrides.json). */
|
|
135
|
+
export declare function getProjectPluginOverridesPath(cwd?: string): string;
|
|
136
|
+
/** Get the primary MCP config file path (first candidate). */
|
|
137
|
+
export declare function getMCPConfigPath(scope: "user" | "project", cwd?: string): string;
|
|
138
|
+
/** Get the SSH config file path. */
|
|
139
|
+
export declare function getSSHConfigPath(scope: "user" | "project", cwd?: string): string;
|
|
140
|
+
/**
|
|
141
|
+
* Persistent per-install UUID stored at `~/.omp/install-id`.
|
|
142
|
+
*
|
|
143
|
+
* Generated lazily on first call and persisted with `O_CREAT|O_EXCL` so
|
|
144
|
+
* concurrent first-call races don't clobber each other (loser re-reads the
|
|
145
|
+
* winner's id). Survives independently of agent state: deleting
|
|
146
|
+
* `~/.omp/agent/` does not regenerate it. Server-side dedup for grievance
|
|
147
|
+
* pushes (and similar telemetry) keys on this id.
|
|
148
|
+
*/
|
|
149
|
+
export declare function getInstallId(): string;
|
|
150
|
+
/** Test-only: clear cached install id. Never call from production code. */
|
|
151
|
+
export declare function __resetInstallIdCacheForTests(): void;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Intentional re-export of Bun.env.
|
|
3
|
+
*
|
|
4
|
+
* All users should import this env module (import { $env } from "@oh-my-pi/pi-utils")
|
|
5
|
+
* before using environment variables. This ensures that .env files have been loaded and
|
|
6
|
+
* overrides (project, home) have been applied, so $env always reflects the correct values.
|
|
7
|
+
*/
|
|
8
|
+
export declare const $env: Record<string, string>;
|
|
9
|
+
/**
|
|
10
|
+
* Resolve the first environment variable value from the given keys.
|
|
11
|
+
* @param keys - The keys to resolve.
|
|
12
|
+
* @returns The first environment variable value, or undefined if no value is found.
|
|
13
|
+
*/
|
|
14
|
+
export declare function $pickenv(...keys: string[]): string | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Parses a positive decimal integer from `$env[name]`.
|
|
17
|
+
* Empty, invalid, NaN, zero, or negative values return `defaultValue`.
|
|
18
|
+
*/
|
|
19
|
+
export declare function $envpos(name: string, defaultValue: number): number;
|
|
20
|
+
/** True when `BUN_ENV` or `NODE_ENV` is the string `test`. */
|
|
21
|
+
export declare function isBunTestRuntime(): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* True when this code is running inside a `bun build --compile` standalone
|
|
24
|
+
* binary. Detects via the embedded virtual-filesystem path markers
|
|
25
|
+
* (`$bunfs`, `~BUN`, or its URL-encoded form `%7EBUN`) in `import.meta.url`,
|
|
26
|
+
* which Bun rewrites for every module bundled into the executable. The
|
|
27
|
+
* `PI_COMPILED` env var (set by the build script's `--define`) is checked
|
|
28
|
+
* first for cheap fast-path detection.
|
|
29
|
+
*/
|
|
30
|
+
export declare function isCompiledBinary(): boolean;
|
|
31
|
+
export declare function $flag(name: string, def?: boolean): boolean;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server-suggested retry delay extraction. Merges the patterns historically used
|
|
3
|
+
* by the OpenAI Codex and Google Gemini retry helpers.
|
|
4
|
+
*
|
|
5
|
+
* Header sources (checked in order):
|
|
6
|
+
* - `Retry-After` (numeric seconds, or HTTP date)
|
|
7
|
+
* - `x-ratelimit-reset` (Unix epoch seconds)
|
|
8
|
+
* - `x-ratelimit-reset-after` (seconds)
|
|
9
|
+
*
|
|
10
|
+
* Body patterns:
|
|
11
|
+
* - `Your quota will reset after 18h31m10s` / `10m15s` / `39s`
|
|
12
|
+
* - `Please retry in 250ms` / `Please retry in 12s`
|
|
13
|
+
* - `"retryDelay": "34.074824224s"` (JSON error detail field)
|
|
14
|
+
* - `try again in 250ms` / `try again in 12s` / `try again in 12sec`
|
|
15
|
+
*
|
|
16
|
+
* Returns `undefined` if no signal is found.
|
|
17
|
+
*/
|
|
18
|
+
export declare function extractRetryHint(source: Response | Headers | null | undefined, body?: string): number | undefined;
|
|
19
|
+
export interface FetchWithRetryOptions extends RequestInit {
|
|
20
|
+
/** Total fetch attempts (initial + retries). Default `5`. */
|
|
21
|
+
maxAttempts?: number;
|
|
22
|
+
/**
|
|
23
|
+
* Per-delay cap. Server-provided `Retry-After` hints exceeding this return
|
|
24
|
+
* the current response immediately — caller deals with the `!response.ok`.
|
|
25
|
+
* Default `60_000`.
|
|
26
|
+
*/
|
|
27
|
+
maxDelayMs?: number;
|
|
28
|
+
/**
|
|
29
|
+
* Fallback delay schedule when no server hint is present. Number, array
|
|
30
|
+
* (indexed by attempt, clamped to last), or function. Default exponential
|
|
31
|
+
* `500ms * 2 ** attempt` capped at `maxDelayMs`.
|
|
32
|
+
*/
|
|
33
|
+
defaultDelayMs?: number | readonly number[] | ((attempt: number) => number);
|
|
34
|
+
/**
|
|
35
|
+
* Optional per-attempt overlay merged into the base `RequestInit` each try.
|
|
36
|
+
* Headers from the overlay shallow-merge over the base. Useful for auth
|
|
37
|
+
* token refresh or user-agent rotation.
|
|
38
|
+
*/
|
|
39
|
+
prepareInit?: (attempt: number) => RequestInit | Promise<RequestInit>;
|
|
40
|
+
/**
|
|
41
|
+
* Optional `fetch` implementation override. Defaults to `globalThis.fetch`.
|
|
42
|
+
* Useful for routing requests through a proxy, instrumented transport, or
|
|
43
|
+
* mock during tests.
|
|
44
|
+
*/
|
|
45
|
+
fetch?: (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Fetch with bounded retries and sensible defaults. Retries on any
|
|
49
|
+
* `isRetryableStatus` (5xx, 408, 429) and on transient network errors. Server
|
|
50
|
+
* `Retry-After`/quota hints are honoured up to `maxDelayMs`; a hint that exceeds
|
|
51
|
+
* the cap returns the current response so the caller can fail fast. Aborts on
|
|
52
|
+
* `init.signal` propagate as `"Request was aborted"`.
|
|
53
|
+
*
|
|
54
|
+
* The caller is responsible for inspecting `!response.ok` once the call returns.
|
|
55
|
+
*/
|
|
56
|
+
export declare function fetchWithRetry(url: string | URL | ((attempt: number) => string | URL), options?: FetchWithRetryOptions): Promise<Response>;
|
|
57
|
+
/**
|
|
58
|
+
* Inspect an arbitrary error value (or its `cause` chain, up to depth 2) for an
|
|
59
|
+
* HTTP status code. Reads `status`, `statusCode`, and `response.status` fields,
|
|
60
|
+
* coerces string values, and falls back to scanning the error message for
|
|
61
|
+
* common patterns like `error (429)` or `HTTP 503`.
|
|
62
|
+
*/
|
|
63
|
+
export declare function extractHttpStatusFromError(error: unknown): number | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* `true` if the given HTTP status code is one we treat as transient: 408
|
|
66
|
+
* (Request Timeout), 429 (Too Many Requests), or any 5xx (server error).
|
|
67
|
+
*/
|
|
68
|
+
export declare function isRetryableStatus(status: number): boolean;
|
|
69
|
+
/**
|
|
70
|
+
* `true` if the message describes an unexpected socket closure — Bun and some
|
|
71
|
+
* proxies surface these for any HTTP/2 stream reset.
|
|
72
|
+
*/
|
|
73
|
+
export declare function isUnexpectedSocketCloseMessage(message: string): boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Identify errors that should be retried: aborts/timeouts in the error name or
|
|
76
|
+
* message, retryable HTTP statuses (see `isRetryableStatus`), unexpected socket
|
|
77
|
+
* closes, and the standard transient phrases. 4xx statuses other than 408/429
|
|
78
|
+
* and validation-shaped messages short-circuit to `false`.
|
|
79
|
+
*/
|
|
80
|
+
export declare function isRetryableError(error: unknown): boolean;
|
|
@@ -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 @oh-my-pi/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,25 @@
|
|
|
1
|
+
export declare class FrontmatterError extends Error {
|
|
2
|
+
readonly source?: unknown;
|
|
3
|
+
constructor(error: Error, source?: unknown);
|
|
4
|
+
toString(): string;
|
|
5
|
+
}
|
|
6
|
+
export interface FrontmatterOptions {
|
|
7
|
+
/** Source of the content (alias: source) */
|
|
8
|
+
location?: unknown;
|
|
9
|
+
/** Source of the content (alias for location) */
|
|
10
|
+
source?: unknown;
|
|
11
|
+
/** Fallback frontmatter values */
|
|
12
|
+
fallback?: Record<string, unknown>;
|
|
13
|
+
/** Normalize the content */
|
|
14
|
+
normalize?: boolean;
|
|
15
|
+
/** Level of error handling */
|
|
16
|
+
level?: "off" | "warn" | "fatal";
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Parse YAML frontmatter from markdown content
|
|
20
|
+
* Returns { frontmatter, body } where body has frontmatter stripped
|
|
21
|
+
*/
|
|
22
|
+
export declare function parseFrontmatter(content: string, options?: FrontmatterOptions): {
|
|
23
|
+
frontmatter: Record<string, unknown>;
|
|
24
|
+
body: string;
|
|
25
|
+
};
|
|
@@ -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 "@oh-my-pi/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,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Intercept `globalThis.fetch` with a middleware-style handler.
|
|
3
|
+
*
|
|
4
|
+
* Returns a `Disposable` so callers can use `using` for automatic cleanup:
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* using _hook = hookFetch((input, init, next) => {
|
|
8
|
+
* if (shouldIntercept(input)) {
|
|
9
|
+
* return new Response("mocked");
|
|
10
|
+
* }
|
|
11
|
+
* return next(input, init);
|
|
12
|
+
* });
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export type FetchHandler = (input: string | URL | Request, init: RequestInit | undefined, next: typeof fetch) => Response | Promise<Response>;
|
|
16
|
+
export declare function hookFetch(handler: FetchHandler): Disposable;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export { createAbortableStream, once, untilAborted } from "./abortable";
|
|
2
|
+
export * from "./async";
|
|
3
|
+
export * from "./color";
|
|
4
|
+
export * from "./dirs";
|
|
5
|
+
export * from "./env";
|
|
6
|
+
export * from "./fetch-retry";
|
|
7
|
+
export * from "./format";
|
|
8
|
+
export * from "./frontmatter";
|
|
9
|
+
export * from "./fs-error";
|
|
10
|
+
export * from "./glob";
|
|
11
|
+
export * from "./hook-fetch";
|
|
12
|
+
export * from "./json";
|
|
13
|
+
export * as logger from "./logger";
|
|
14
|
+
export * from "./mermaid-ascii";
|
|
15
|
+
export * from "./mime";
|
|
16
|
+
export * from "./peek-file";
|
|
17
|
+
export * as postmortem from "./postmortem";
|
|
18
|
+
export * as procmgr from "./procmgr";
|
|
19
|
+
export * as prompt from "./prompt";
|
|
20
|
+
export * as ptree from "./ptree";
|
|
21
|
+
export { AbortError, ChildProcess, Exception, NonZeroExitError } from "./ptree";
|
|
22
|
+
export * from "./sanitize-text";
|
|
23
|
+
export * from "./snowflake";
|
|
24
|
+
export * from "./stream";
|
|
25
|
+
export * from "./tab-spacing";
|
|
26
|
+
export * from "./temp";
|
|
27
|
+
export * from "./type-guards";
|
|
28
|
+
export * from "./which";
|
|
29
|
+
export declare function structuredCloneJSON<T>(value: T): T;
|