jeopi-utils 16.2.14 → 16.2.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/dist/types/abortable.d.ts +32 -0
  2. package/dist/types/async.d.ts +6 -0
  3. package/dist/types/binary.d.ts +17 -0
  4. package/dist/types/cli.d.ts +117 -0
  5. package/dist/types/color.d.ts +102 -0
  6. package/dist/types/dirs.d.ts +289 -0
  7. package/dist/types/env.d.ts +74 -0
  8. package/dist/types/fetch-retry.d.ts +94 -0
  9. package/dist/types/format.d.ts +37 -0
  10. package/dist/types/frontmatter.d.ts +25 -0
  11. package/dist/types/fs-error.d.ts +31 -0
  12. package/dist/types/glob.d.ts +28 -0
  13. package/dist/types/index.d.ts +35 -0
  14. package/dist/types/json-parse.d.ts +48 -0
  15. package/dist/types/json.d.ts +4 -0
  16. package/dist/types/logger.d.ts +83 -0
  17. package/dist/types/loop-phase.d.ts +10 -0
  18. package/dist/types/mermaid-ascii.d.ts +11 -0
  19. package/dist/types/mime.d.ts +29 -0
  20. package/dist/types/module-timer.d.ts +1 -0
  21. package/dist/types/path-tree.d.ts +76 -0
  22. package/dist/types/path.d.ts +2 -0
  23. package/dist/types/peek-file.d.ts +29 -0
  24. package/dist/types/postmortem.d.ts +37 -0
  25. package/dist/types/procmgr.d.ts +29 -0
  26. package/dist/types/prompt.d.ts +18 -0
  27. package/dist/types/ptree.d.ts +108 -0
  28. package/dist/types/ring.d.ts +93 -0
  29. package/dist/types/runtime-install.d.ts +68 -0
  30. package/dist/types/sanitize-text.d.ts +29 -0
  31. package/dist/types/snowflake.d.ts +25 -0
  32. package/dist/types/stream.d.ts +68 -0
  33. package/dist/types/tab-spacing.d.ts +24 -0
  34. package/dist/types/temp.d.ts +17 -0
  35. package/dist/types/timing-buffer.d.ts +22 -0
  36. package/dist/types/tls-fetch.d.ts +37 -0
  37. package/dist/types/type-guards.d.ts +3 -0
  38. package/dist/types/vendor/mermaid-ascii/ascii/ansi.d.ts +41 -0
  39. package/dist/types/vendor/mermaid-ascii/ascii/canvas.d.ts +89 -0
  40. package/dist/types/vendor/mermaid-ascii/ascii/class-diagram.d.ts +7 -0
  41. package/dist/types/vendor/mermaid-ascii/ascii/converter.d.ts +12 -0
  42. package/dist/types/vendor/mermaid-ascii/ascii/draw.d.ts +66 -0
  43. package/dist/types/vendor/mermaid-ascii/ascii/edge-bundling.d.ts +48 -0
  44. package/dist/types/vendor/mermaid-ascii/ascii/edge-routing.d.ts +43 -0
  45. package/dist/types/vendor/mermaid-ascii/ascii/er-diagram.d.ts +7 -0
  46. package/dist/types/vendor/mermaid-ascii/ascii/grid.d.ts +56 -0
  47. package/dist/types/vendor/mermaid-ascii/ascii/index.d.ts +65 -0
  48. package/dist/types/vendor/mermaid-ascii/ascii/multiline-utils.d.ts +27 -0
  49. package/dist/types/vendor/mermaid-ascii/ascii/pathfinder.d.ts +17 -0
  50. package/dist/types/vendor/mermaid-ascii/ascii/sequence.d.ts +7 -0
  51. package/dist/types/vendor/mermaid-ascii/ascii/shapes/circle.d.ts +11 -0
  52. package/dist/types/vendor/mermaid-ascii/ascii/shapes/corners.d.ts +34 -0
  53. package/dist/types/vendor/mermaid-ascii/ascii/shapes/diamond.d.ts +11 -0
  54. package/dist/types/vendor/mermaid-ascii/ascii/shapes/hexagon.d.ts +11 -0
  55. package/dist/types/vendor/mermaid-ascii/ascii/shapes/index.d.ts +26 -0
  56. package/dist/types/vendor/mermaid-ascii/ascii/shapes/rectangle.d.ts +31 -0
  57. package/dist/types/vendor/mermaid-ascii/ascii/shapes/rounded.d.ts +11 -0
  58. package/dist/types/vendor/mermaid-ascii/ascii/shapes/special.d.ts +59 -0
  59. package/dist/types/vendor/mermaid-ascii/ascii/shapes/stadium.d.ts +17 -0
  60. package/dist/types/vendor/mermaid-ascii/ascii/shapes/state.d.ts +30 -0
  61. package/dist/types/vendor/mermaid-ascii/ascii/shapes/types.d.ts +55 -0
  62. package/dist/types/vendor/mermaid-ascii/ascii/types.d.ts +206 -0
  63. package/dist/types/vendor/mermaid-ascii/ascii/validate.d.ts +51 -0
  64. package/dist/types/vendor/mermaid-ascii/ascii/xychart.d.ts +2 -0
  65. package/dist/types/vendor/mermaid-ascii/class/parser.d.ts +6 -0
  66. package/dist/types/vendor/mermaid-ascii/class/types.d.ts +102 -0
  67. package/dist/types/vendor/mermaid-ascii/er/parser.d.ts +6 -0
  68. package/dist/types/vendor/mermaid-ascii/er/types.d.ts +76 -0
  69. package/dist/types/vendor/mermaid-ascii/index.d.ts +1 -0
  70. package/dist/types/vendor/mermaid-ascii/multiline-utils.d.ts +9 -0
  71. package/dist/types/vendor/mermaid-ascii/parser.d.ts +7 -0
  72. package/dist/types/vendor/mermaid-ascii/sequence/parser.d.ts +6 -0
  73. package/dist/types/vendor/mermaid-ascii/sequence/types.d.ts +130 -0
  74. package/dist/types/vendor/mermaid-ascii/text-metrics.d.ts +21 -0
  75. package/dist/types/vendor/mermaid-ascii/types.d.ts +114 -0
  76. package/dist/types/vendor/mermaid-ascii/xychart/colors.d.ts +25 -0
  77. package/dist/types/vendor/mermaid-ascii/xychart/parser.d.ts +6 -0
  78. package/dist/types/vendor/mermaid-ascii/xychart/types.d.ts +145 -0
  79. package/dist/types/which.d.ts +37 -0
  80. package/dist/types/worker-host.d.ts +47 -0
  81. package/package.json +6 -6
  82. package/src/dirs.ts +20 -20
@@ -0,0 +1,32 @@
1
+ export declare class AbortError extends Error {
2
+ constructor(signal: AbortSignal);
3
+ }
4
+ /**
5
+ * Abortable async iteration over a {@link ReadableStream}. Reads the source
6
+ * reader directly and yields each chunk, so the consumer's `for await` drives a
7
+ * single read loop with no intermediate stream or per-chunk enqueue.
8
+ *
9
+ * Unlike `stream.pipeThrough(..., { signal })`, this explicitly cancels the
10
+ * source reader on abort or early `break`, propagating HTTP-client disconnects
11
+ * and watchdog timeouts to the backend request instead of only stopping the
12
+ * local consumer. On abort it throws {@link AbortError}; the lock is released
13
+ * on completion, abort, throw, or early exit. The source is cancelled only on
14
+ * abort or early exit — never on natural EOF.
15
+ */
16
+ export declare function abortableSource<T>(stream: ReadableStream<T>, signal?: AbortSignal): AsyncGenerator<T>;
17
+ /**
18
+ * Runs a promise-returning function (`pr`). If the given AbortSignal is aborted before or during
19
+ * execution, the promise is rejected with a standard error.
20
+ *
21
+ * @param signal - Optional AbortSignal to cancel the operation
22
+ * @param pr - Function returning a promise to run
23
+ * @returns Promise resolving as `pr` would, or rejecting on abort
24
+ */
25
+ export declare function untilAborted<T>(signal: AbortSignal | undefined | null, pr: Promise<T> | (() => Promise<T>)): Promise<T>;
26
+ /**
27
+ * Memoizes a function with no arguments, calling it once and caching the result.
28
+ *
29
+ * @param fn - Function to be called once
30
+ * @returns A function that returns the cached result of `fn`
31
+ */
32
+ 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,17 @@
1
+ /**
2
+ * Classify an in-memory byte header as binary (non-UTF-8-text).
3
+ *
4
+ * Binary when the header contains a NUL byte (true binary, plus UTF-16/UTF-32
5
+ * text whose ASCII range is NUL-padded) or when it is not valid UTF-8. The
6
+ * decode runs in streaming mode so a multibyte sequence truncated at the header
7
+ * boundary is tolerated, while any genuinely invalid byte still fails — matching
8
+ * the strict `fatal` decode the `local://`/`ssh://` read paths already use.
9
+ */
10
+ export declare function isProbablyBinaryHeader(header: Uint8Array): boolean;
11
+ /**
12
+ * Sniff the first {@link BINARY_SNIFF_BYTES} of `filePath` and report whether it
13
+ * is binary (non-UTF-8-text). See {@link isProbablyBinaryHeader} for the rule.
14
+ */
15
+ export declare function isProbablyBinary(filePath: string, maxBytes?: number): Promise<boolean>;
16
+ /** Synchronous {@link isProbablyBinary}. */
17
+ export declare function isProbablyBinarySync(filePath: string, maxBytes?: number): boolean;
@@ -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 extends FlagInput>(opts?: T): FlagDescriptor<"boolean"> & T;
35
+ integer<T extends FlagInput & {
36
+ default?: number;
37
+ }>(opts?: T): FlagDescriptor<"integer"> & T;
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,102 @@
1
+ /**
2
+ * Color manipulation utilities for hex colors.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * import { hexToHsv, hsvToHex } from "jeopi-utils";
7
+ *
8
+ * // Rotate the hue by 90°
9
+ * const hsv = hexToHsv("#4ade80");
10
+ * hsv.h = (hsv.h + 90) % 360;
11
+ * const newHex = hsvToHex(hsv);
12
+ * ```
13
+ */
14
+ export interface HSV {
15
+ /** Hue in degrees (0-360) */
16
+ h: number;
17
+ /** Saturation (0-1) */
18
+ s: number;
19
+ /** Value/brightness (0-1) */
20
+ v: number;
21
+ }
22
+ export interface RGB {
23
+ /** Red (0-255) */
24
+ r: number;
25
+ /** Green (0-255) */
26
+ g: number;
27
+ /** Blue (0-255) */
28
+ b: number;
29
+ }
30
+ /**
31
+ * Parse a hex color string to RGB.
32
+ * Supports #RGB, #RRGGBB formats.
33
+ */
34
+ export declare function hexToRgb(hex: string): RGB;
35
+ /**
36
+ * Convert RGB to hex color string.
37
+ */
38
+ export declare function rgbToHex(rgb: RGB): string;
39
+ /**
40
+ * Convert RGB to HSV.
41
+ */
42
+ export declare function rgbToHsv(rgb: RGB): HSV;
43
+ /**
44
+ * Convert HSV to RGB.
45
+ */
46
+ export declare function hsvToRgb(hsv: HSV): RGB;
47
+ /**
48
+ * Convert hex color to HSV.
49
+ */
50
+ export declare function hexToHsv(hex: string): HSV;
51
+ /**
52
+ * Convert HSV to hex color.
53
+ */
54
+ export declare function hsvToHex(hsv: HSV): string;
55
+ /**
56
+ * Shift the hue of a hex color by a given number of degrees.
57
+ */
58
+ export declare function shiftHue(hex: string, degrees: number): string;
59
+ export interface HSVAdjustment {
60
+ /** Hue shift in degrees (additive) */
61
+ h?: number;
62
+ /** Saturation multiplier */
63
+ s?: number;
64
+ /** Value/brightness multiplier */
65
+ v?: number;
66
+ }
67
+ /**
68
+ * Adjust HSV components of a hex color.
69
+ *
70
+ * @param hex - Hex color string (#RGB or #RRGGBB)
71
+ * @param adj - Adjustments: h is additive degrees, s and v are multipliers
72
+ * @returns New hex color string
73
+ *
74
+ * @example
75
+ * ```ts
76
+ * // Shift hue +60°, reduce saturation to 71%
77
+ * adjustHsv("#00ff88", { h: 60, s: 0.71 }) // "#4a9eff"
78
+ * ```
79
+ */
80
+ export declare function adjustHsv(hex: string, adj: HSVAdjustment): string;
81
+ /**
82
+ * Convert HSL (h: 0-360, s: 0-1, l: 0-1) to a CSS hex string.
83
+ */
84
+ export declare function hslToHex(h: number, s: number, l: number): string;
85
+ /**
86
+ * Perceptual luma (gamma-encoded BT.709 weights over raw sRGB), normalized to 0..1.
87
+ *
88
+ * Accepts a hex string (`#rgb` / `#rrggbb`) or a 256-color palette index; returns
89
+ * `undefined` for var refs, empty strings, or anything unparseable.
90
+ *
91
+ * Cheap and good enough for a light/dark *classification* threshold. NOT suitable
92
+ * for contrast ratios — use {@link relativeLuminance} for those.
93
+ */
94
+ export declare function colorLuma(value: string | number): number | undefined;
95
+ /**
96
+ * WCAG 2.x relative luminance (BT.709 weights over linearized sRGB), normalized to
97
+ * 0..1. This is the value the WCAG contrast-ratio formula expects.
98
+ *
99
+ * Accepts a hex string (`#rgb` / `#rrggbb`) or a 256-color palette index; returns
100
+ * `undefined` for var refs, empty strings, or anything unparseable.
101
+ */
102
+ export declare function relativeLuminance(value: string | number): number | undefined;
@@ -0,0 +1,289 @@
1
+ /**
2
+ * Centralized path helpers for jeopi config directories.
3
+ *
4
+ * Uses PI_CONFIG_DIR (default ".jeopi") 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/jeopi/. This requires running `jeopi config init-xdg` first to
10
+ * move data to the new locations. No filesystem existence checks are performed
11
+ * — if the env var is set, jeopi trusts that the migration has been done.
12
+ */
13
+ /** App name (e.g. "jeopi") */
14
+ export declare const APP_NAME: string;
15
+ /** Config directory name (e.g. ".jeopi") */
16
+ export declare const CONFIG_DIR_NAME: string;
17
+ /** Pre-rebrand config directory name, kept only to detect and migrate unmigrated installs. */
18
+ export declare const LEGACY_CONFIG_DIR_NAME: string;
19
+ /** Version (e.g. "1.0.0") */
20
+ export declare const VERSION: string;
21
+ /** Minimum Bun version */
22
+ export declare const MIN_BUN_VERSION: string;
23
+ /**
24
+ * Normalize and validate a profile name. Returns `undefined` for the implicit
25
+ * default (empty string, whitespace, or the explicit "default" sentinel) and
26
+ * throws for syntactically invalid or platform-reserved names.
27
+ *
28
+ * Exported so consumers of `jeopi-utils/dirs` (CLI bootstrap, tests,
29
+ * downstream tools) can validate user input without re-deriving the rules.
30
+ */
31
+ export declare function normalizeProfileName(profile: string | undefined): string | undefined;
32
+ /**
33
+ * Resolve the active profile from the two profile env vars. `JEOPI_PROFILE` is
34
+ * the canonical variable and takes precedence; `PI_PROFILE` is the legacy
35
+ * compatibility fallback, consulted only when `JEOPI_PROFILE` is undefined. An
36
+ * explicitly-empty `JEOPI_PROFILE` therefore selects the default profile rather
37
+ * than silently inheriting `PI_PROFILE`. Delegates validation/normalization to
38
+ * {@link normalizeProfileName} (which throws on a syntactically invalid value).
39
+ */
40
+ export declare function resolveProfileEnv(jeopi: string | undefined, pi: string | undefined): string | undefined;
41
+ export declare function resolveEquivalentPath(inputPath: string): string;
42
+ export declare function normalizePathForComparison(inputPath: string): string;
43
+ export declare function pathIsWithin(root: string, candidate: string): boolean;
44
+ export declare function relativePathWithinRoot(root: string, candidate: string): string | null;
45
+ /** Get the project directory. */
46
+ export declare function getProjectDir(): string;
47
+ /** Set the project directory. */
48
+ export declare function setProjectDir(dir: string): void;
49
+ /**
50
+ * Whether `dir` resolves to an existing directory. Any stat failure — a deleted
51
+ * path (ENOENT), permission error, or a non-directory — returns `false`, so
52
+ * callers can decide whether a directory is safe to `chdir` into or adopt as a
53
+ * working directory before {@link setProjectDir} throws on it.
54
+ */
55
+ export declare function directoryExists(dir: string): Promise<boolean>;
56
+ /** Get the config directory name relative to home (e.g. ".jeopi" or PI_CONFIG_DIR override). */
57
+ export declare function getConfigDirName(): string;
58
+ /** Get the config agent directory name relative to home (e.g. ".jeopi/agent" or PI_CONFIG_DIR + "/agent"). */
59
+ export declare function getConfigAgentDirName(): string;
60
+ /**
61
+ * Rebuild the dirs resolver from the current environment, reusing the profile
62
+ * resolved at module load. Directory-affecting keys (XDG_*_HOME and, in default
63
+ * mode, `PI_CODING_AGENT_DIR`) loaded from a profile/agent `.env` only reach
64
+ * `process.env` *after* this module froze the resolver at import time, so
65
+ * `env.ts` calls this once after applying its `.env` files. The agent `.env`
66
+ * location derives from the profile name + home before this runs, so the
67
+ * rebuild re-reads only the directory vars, never the profile selection. The
68
+ * `preProfileAgentDirEnv` snapshot is intentionally left untouched.
69
+ */
70
+ export declare function refreshDirsFromEnv(): void;
71
+ /** Get the config root directory (~/.jeopi). */
72
+ export declare function getConfigRootDir(): string;
73
+ /**
74
+ * Whether an unmigrated pre-rebrand config directory exists at `~/.omp` while
75
+ * the new `~/.jeopi` root does not. Read-only — never renames anything. Used
76
+ * by CLI startup to print a one-time migration hint and by `{APP_NAME} config
77
+ * migrate-legacy` to decide whether there is anything to do.
78
+ *
79
+ * Always `false` when `PI_CONFIG_DIR` is set: an explicit override means the
80
+ * user already manages their own directory name and the legacy default is
81
+ * irrelevant.
82
+ */
83
+ export declare function hasUnmigratedLegacyConfigDir(): boolean;
84
+ /**
85
+ * Rename `~/.omp` to `~/.jeopi` in place, carrying over auth, sessions,
86
+ * settings, and every profile in one atomic move. Explicit and opt-in
87
+ * (`{APP_NAME} config migrate-legacy`) — never invoked automatically at
88
+ * module load or from {@link DirResolver}, so a running process never renames
89
+ * a directory another concurrent process might have open.
90
+ *
91
+ * Throws if `PI_CONFIG_DIR` is set, if `~/.omp` does not exist, or if
92
+ * `~/.jeopi` already exists (refuses to clobber). Callers own reporting;
93
+ * this performs the single `fs.renameSync` and nothing else — no cache
94
+ * invalidation, since the resolver reads `os.homedir()` fresh on next use.
95
+ */
96
+ export declare function migrateLegacyConfigDir(): {
97
+ from: string;
98
+ to: string;
99
+ };
100
+ /** Set the coding agent directory. Creates a fresh resolver, invalidating all cached paths. */
101
+ export declare function setAgentDir(dir: string): void;
102
+ /**
103
+ * Test-only: reset the pre-profile `PI_CODING_AGENT_DIR` snapshot to whatever
104
+ * the current environment looks like. Cross-suite test pollution can otherwise
105
+ * leak a stale snapshot through `setAgentDir` and corrupt `setProfile(undefined)`
106
+ * restore semantics. Production code MUST NOT call this — the snapshot's
107
+ * lifecycle is owned by `setAgentDir` / `setProfile` and a runtime caller has
108
+ * no business clearing it.
109
+ */
110
+ export declare function __resetProfileSnapshotForTests(): void;
111
+ /**
112
+ * Test-only: rebuild profile + directory state from the current process env.
113
+ * Production code keeps the module-load profile stable; tests that mutate
114
+ * `setAgentDir`/`setProfile` need an exact restore point after they put env vars
115
+ * back.
116
+ */
117
+ export declare function __resetDirsFromEnvForTests(): void;
118
+ /** Activate a named profile. Passing undefined or "default" returns to the default profile. */
119
+ export declare function setProfile(profile: string | undefined): void;
120
+ /** Get the active named profile. Undefined means the default profile. */
121
+ export declare function getActiveProfile(): string | undefined;
122
+ /** Resolve the config root that backs a profile without activating it. */
123
+ export declare function getProfileRootDir(profile: string | undefined): string;
124
+ /** Get the agent config directory (~/.jeopi/agent). */
125
+ export declare function getAgentDir(): string;
126
+ /** Get the project-local config directory (.jeopi). */
127
+ export declare function getProjectAgentDir(cwd?: string): string;
128
+ /** Get the reports directory (~/.jeopi/reports). */
129
+ export declare function getReportsDir(): string;
130
+ /** Get the logs directory (~/.jeopi/logs). */
131
+ export declare function getLogsDir(): string;
132
+ /** Get the path to a dated log file (~/.jeopi/logs/jeopi.YYYY-MM-DD.log). */
133
+ export declare function getLogPath(date?: Date): string;
134
+ /**
135
+ * Get the plugins directory (~/.jeopi/plugins or its XDG equivalent).
136
+ *
137
+ * No-arg form (production callers) goes through the XDG-aware DirResolver so
138
+ * reads and writes always agree. The optional `home` parameter is for test
139
+ * isolation: when it differs from `os.homedir()` it short-circuits the resolver
140
+ * and returns `<home>/<configDir>/plugins` so tests with a temp HOME get a
141
+ * deterministic path. Passing `os.homedir()` explicitly is identical to the
142
+ * no-arg form — XDG semantics are preserved.
143
+ */
144
+ export declare function getPluginsDir(home?: string): string;
145
+ /** Where npm installs packages (~/.jeopi/plugins/node_modules). */
146
+ export declare function getPluginsNodeModules(home?: string): string;
147
+ /** Plugin manifest (~/.jeopi/plugins/package.json). */
148
+ export declare function getPluginsPackageJson(home?: string): string;
149
+ /** Plugin lock file (~/.jeopi/plugins/omp-plugins.lock.json). */
150
+ export declare function getPluginsLockfile(home?: string): string;
151
+ /** Get the remote mount directory (~/.jeopi/remote). */
152
+ export declare function getRemoteDir(): string;
153
+ /**
154
+ * Relocate the base directory for agent-managed worktrees (PR checkouts, task
155
+ * isolation, and `jeopi worktree` cleanup all read the same base). Driven by the
156
+ * `worktree.base` setting in coding-agent; pass `undefined`/empty to clear and
157
+ * fall back to `JEOPI_WORKTREE_DIR` or the `~/.jeopi/wt` default.
158
+ *
159
+ * `~` is expanded and a relative path is rejected (see {@link resolveWorktreeBase}).
160
+ * Returns the absolute path that took effect, or `undefined` if the input was
161
+ * cleared or rejected — callers can warn on a non-empty input that returns
162
+ * `undefined`.
163
+ */
164
+ export declare function setWorktreesDir(dir: string | undefined): string | undefined;
165
+ /**
166
+ * Get the agent-managed worktrees directory. Resolution order: the
167
+ * `JEOPI_WORKTREE_DIR` env var, then the {@link setWorktreesDir} override (the
168
+ * `worktree.base` setting), then the `~/.jeopi/wt` default. The env var and the
169
+ * override are both `~`-expanded and must be absolute; a relative value is
170
+ * ignored and resolution falls through.
171
+ */
172
+ export declare function getWorktreesDir(): string;
173
+ /** Get the SSH control socket directory (~/.jeopi/ssh-control). */
174
+ export declare function getSshControlDir(): string;
175
+ /** Get the remote host info directory (~/.jeopi/remote-host). */
176
+ export declare function getRemoteHostDir(): string;
177
+ /** Get the managed Python venv directory (~/.jeopi/python-env). */
178
+ export declare function getPythonEnvDir(): string;
179
+ /** Get the shared Python gateway state directory (~/.jeopi/agent/python-gateway; XDG default: $XDG_STATE_HOME/jeopi/python-gateway). */
180
+ export declare function getPythonGatewayDir(): string;
181
+ /** Get the puppeteer sandbox directory (~/.jeopi/puppeteer). */
182
+ export declare function getPuppeteerDir(): string;
183
+ /** Get DOCS_RS cache directory () */
184
+ export declare function getDocsRsCacheDir(): string;
185
+ /**Get AutoQa db directory */
186
+ export declare function getAutoQaDbDir(): string;
187
+ /**
188
+ * Stable 7-character hex digest of an absolute filesystem path.
189
+ *
190
+ * Used to pack the project identity into a single short fs-safe segment
191
+ * (e.g. PR-checkout and task-isolation worktree dirs under `~/.jeopi/wt/`).
192
+ * Bun.hash is non-cryptographic — collision space is ~2^28, which is fine
193
+ * for naming a handful of repos on a single machine. Same input on the
194
+ * same Bun runtime yields the same output.
195
+ */
196
+ export declare function hashPath(absPath: string): string;
197
+ /** Get the path to a single worktree directory (~/.jeopi/wt/<segment>). */
198
+ export declare function getWorktreeDir(segment: string): string;
199
+ /** Get the GPU cache path (~/.jeopi/gpu_cache.json). */
200
+ export declare function getGpuCachePath(): string;
201
+ /**
202
+ * Get the GitHub view cache database path (~/.jeopi/cache/github-cache.db).
203
+ * Honors the `JEOPI_GITHUB_CACHE_DB` env var when set so tests can isolate the
204
+ * cache file without touching the rest of the config root.
205
+ */
206
+ export declare function getGithubCacheDbPath(): string;
207
+ /**
208
+ * Get the encrypted auth-broker snapshot cache path (~/.jeopi/cache/auth-broker-snapshot.enc).
209
+ * Honors the `JEOPI_AUTH_BROKER_SNAPSHOT_CACHE` env var when set so tests and
210
+ * operators can isolate or relocate the cache file.
211
+ */
212
+ export declare function getAuthBrokerSnapshotCachePath(): string;
213
+ /** Get the local FastEmbed model cache directory (~/.jeopi/cache/fastembed). */
214
+ export declare function getFastembedCacheDir(): string;
215
+ /** Get the on-demand fastembed runtime install root (~/.jeopi/cache/fastembed-runtime). */
216
+ export declare function getFastembedRuntimeDir(): string;
217
+ /** Get the natives directory (~/.jeopi/natives). */
218
+ export declare function getNativesDir(): string;
219
+ /** Get the stats database path (~/.jeopi/stats.db). */
220
+ export declare function getStatsDbPath(): string;
221
+ /** Get the autoresearch state directory (~/.jeopi/autoresearch). */
222
+ export declare function getAutoresearchDir(): string;
223
+ /** Get the per-project autoresearch state directory (~/.jeopi/autoresearch/<encoded-project>). */
224
+ export declare function getAutoresearchProjectDir(encodedProject: string): string;
225
+ /** Get the per-project autoresearch SQLite database path (~/.jeopi/autoresearch/<encoded-project>.db). */
226
+ export declare function getAutoresearchDbPath(encodedProject: string): string;
227
+ /** Get the per-run artifact directory (~/.jeopi/autoresearch/<encoded-project>/runs/<runId>). */
228
+ export declare function getAutoresearchRunDir(encodedProject: string, runId: number): string;
229
+ /** Get the path to agent.db (SQLite database for settings and auth storage). */
230
+ export declare function getAgentDbPath(agentDir?: string): string;
231
+ /** Get the last-seen-changelog-version marker file (~/.jeopi/agent/last-changelog-version). */
232
+ export declare function getLastChangelogVersionPath(agentDir?: string): string;
233
+ /** Get the path to history.db (SQLite database for session history). */
234
+ export declare function getHistoryDbPath(agentDir?: string): string;
235
+ /** Get the path to models.db (model cache database). */
236
+ export declare function getModelDbPath(agentDir?: string): string;
237
+ /** Get the tiny title model cache directory (~/.jeopi/agent/cache/tiny-models). */
238
+ export declare function getTinyModelsCacheDir(agentDir?: string): string;
239
+ /** Get the document conversion cache directory (~/.jeopi/agent/cache/document-conversions; XDG default: $XDG_CACHE_HOME/jeopi/cache/document-conversions). */
240
+ export declare function getDocumentConversionCacheDir(agentDir?: string): string;
241
+ /** Get the sessions directory (~/.jeopi/agent/sessions). */
242
+ export declare function getSessionsDir(agentDir?: string): string;
243
+ /** Get the content-addressed blob store directory (~/.jeopi/agent/blobs). */
244
+ export declare function getBlobsDir(agentDir?: string): string;
245
+ /** Get the custom themes directory (~/.jeopi/agent/themes). */
246
+ export declare function getCustomThemesDir(agentDir?: string): string;
247
+ /** Get the tools directory (~/.jeopi/agent/tools). */
248
+ export declare function getToolsDir(agentDir?: string): string;
249
+ /** Get the slash commands directory (~/.jeopi/agent/commands). */
250
+ export declare function getCommandsDir(agentDir?: string): string;
251
+ /** Get the prompts directory (~/.jeopi/agent/prompts). */
252
+ export declare function getPromptsDir(agentDir?: string): string;
253
+ /** Get the user-level Python modules directory (~/.jeopi/agent/modules). */
254
+ export declare function getAgentModulesDir(agentDir?: string): string;
255
+ /** Get the memories directory (~/.jeopi/agent/memories). */
256
+ export declare function getMemoriesDir(agentDir?: string): string;
257
+ /** Get the terminal sessions directory (~/.jeopi/agent/terminal-sessions). */
258
+ export declare function getTerminalSessionsDir(agentDir?: string): string;
259
+ /** Get the crash log path (~/.jeopi/agent/jeopi-crash.log). */
260
+ export declare function getCrashLogPath(agentDir?: string): string;
261
+ /** Get the debug log path (~/.jeopi/agent/jeopi-debug.log). */
262
+ export declare function getDebugLogPath(agentDir?: string): string;
263
+ /** Get the project-level Python modules directory (.jeopi/modules). */
264
+ export declare function getProjectModulesDir(cwd?: string): string;
265
+ /** Get the project-level prompts directory (.jeopi/prompts). */
266
+ export declare function getProjectPromptsDir(cwd?: string): string;
267
+ /** Get the project-level plugin overrides path (.jeopi/plugin-overrides.json). */
268
+ export declare function getProjectPluginOverridesPath(cwd?: string): string;
269
+ /** Get the primary MCP config file path (first candidate). */
270
+ export declare function getMCPConfigPath(scope: "user" | "project", cwd?: string): string;
271
+ /** Get the SSH config file path. */
272
+ export declare function getSSHConfigPath(scope: "user" | "project", cwd?: string): string;
273
+ /**
274
+ * Persistent per-install UUID stored at `~/.jeopi/install-id`.
275
+ *
276
+ * Generated lazily on first call and persisted with `O_CREAT|O_EXCL` so
277
+ * concurrent first-call races don't clobber each other (loser re-reads the
278
+ * winner's id). Survives independently of agent state: deleting
279
+ * `~/.jeopi/agent/` does not regenerate it. Server-side dedup for grievance
280
+ * pushes (and similar telemetry) keys on this id.
281
+ *
282
+ * Anchored to the base config root (`~/.jeopi/install-id`) regardless of the
283
+ * active profile: install identity is per-install, not per-profile, so every
284
+ * profile shares one id and the global cache stays correct no matter the
285
+ * profile / `getInstallId` call order.
286
+ */
287
+ export declare function getInstallId(): string;
288
+ /** Test-only: clear cached install id. Never call from production code. */
289
+ export declare function __resetInstallIdCacheForTests(): void;
@@ -0,0 +1,74 @@
1
+ export * from "./worker-host";
2
+ /**
3
+ * Strict shell-identifier shape. Used for dotenv keys we accept into
4
+ * `Bun.env` — those should be referenceable as `$NAME` from POSIX shells,
5
+ * so we reject anything outside `[A-Za-z_][A-Za-z0-9_]*`.
6
+ */
7
+ export declare function isValidEnvName(name: string): boolean;
8
+ /**
9
+ * The only names that are genuinely unsafe to forward to a native `execve`
10
+ * spawn: empty, containing `=` (would corrupt the `KEY=VALUE` framing) or
11
+ * NUL (terminates the C string mid-entry). Windows ships standard variables
12
+ * whose names contain parentheses (e.g. `ProgramFiles(x86)`, `CommonProgramFiles(x86)`)
13
+ * — those MUST survive the scrub so downstream resolvers (Git Bash discovery
14
+ * in `procmgr.ts`, etc.) can still read them.
15
+ */
16
+ export declare function isSafeEnvName(name: string): boolean;
17
+ export declare function isSafeEnvValue(value: string): boolean;
18
+ export declare function isMacosMallocStackLoggingEnvName(name: string): boolean;
19
+ export declare function filterProcessEnv(env: Record<string, string | undefined>): Record<string, string>;
20
+ /**
21
+ * Parses a .env file synchronously and extracts key-value string pairs.
22
+ * Ignores lines that are empty or start with '#'. Trims whitespace.
23
+ * Allows values to be quoted with single or double quotes.
24
+ * Returns an object of key-value pairs.
25
+ */
26
+ export declare function parseEnvFile(filePath: string): Record<string, string>;
27
+ /**
28
+ * Intentional re-export of Bun.env.
29
+ *
30
+ * All users should import this env module (import { $env } from "jeopi-utils")
31
+ * before using environment variables. This ensures that .env files have been loaded and
32
+ * overrides (project, home) have been applied, so $env always reflects the correct values.
33
+ */
34
+ export declare const $env: Record<string, string>;
35
+ /**
36
+ * Resolve the first environment variable value from the given keys.
37
+ * @param keys - The keys to resolve.
38
+ * @returns The first environment variable value, or undefined if no value is found.
39
+ */
40
+ export declare function $pickenv(...keys: string[]): string | undefined;
41
+ /**
42
+ * Parses a positive decimal integer from `$env[name]`.
43
+ * Empty, invalid, NaN, zero, or negative values return `defaultValue`.
44
+ */
45
+ export declare function $envpos(name: string, defaultValue: number): number;
46
+ /** True when `BUN_ENV` or `NODE_ENV` is the string `test`. */
47
+ export declare function isBunTestRuntime(): boolean;
48
+ /**
49
+ * True when real-terminal side effects must be suppressed: stdout escape/frame
50
+ * writes, stdin raw-mode + resume, CSI/OSC capability probes, SIGWINCH, window
51
+ * title changes, and emergency restore. Defaults to {@link isBunTestRuntime} so
52
+ * `bun test` launched inside a real TTY never paints the TUI, leaks probe
53
+ * queries, or hijacks the developer's stdin; production runtimes stay
54
+ * interactive.
55
+ *
56
+ * Terminal-contract tests that must exercise the real I/O path opt out with
57
+ * `setTerminalHeadless(false)` and restore it afterwards.
58
+ */
59
+ export declare function isTerminalHeadless(): boolean;
60
+ /**
61
+ * Override the {@link isTerminalHeadless} default and return the previous value
62
+ * so callers can restore exact prior state (`const prev = setTerminalHeadless(false); … setTerminalHeadless(prev);`).
63
+ */
64
+ export declare function setTerminalHeadless(headless: boolean): boolean;
65
+ /**
66
+ * True when this code is running inside a `bun build --compile` standalone
67
+ * binary. Detects via the embedded virtual-filesystem path markers
68
+ * (`$bunfs`, `~BUN`, or its URL-encoded form `%7EBUN`) in `import.meta.url`,
69
+ * which Bun rewrites for every module bundled into the executable. The
70
+ * `PI_COMPILED` env var (set by the build script's `--define`) is checked
71
+ * first for cheap fast-path detection.
72
+ */
73
+ export declare function isCompiledBinary(): boolean;
74
+ export declare function $flag(name: string, def?: boolean): boolean;