@oh-my-pi-zen/pi-utils 16.3.6-zen.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +245 -0
- package/README.md +36 -0
- package/dist/types/abortable.d.ts +32 -0
- package/dist/types/async.d.ts +6 -0
- package/dist/types/binary.d.ts +17 -0
- package/dist/types/cli.d.ts +117 -0
- package/dist/types/color.d.ts +102 -0
- package/dist/types/dirs.d.ts +260 -0
- package/dist/types/env.d.ts +74 -0
- package/dist/types/fetch-retry.d.ts +94 -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/index.d.ts +35 -0
- package/dist/types/json-parse.d.ts +48 -0
- package/dist/types/json.d.ts +4 -0
- package/dist/types/logger.d.ts +83 -0
- package/dist/types/loop-phase.d.ts +10 -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 +37 -0
- package/dist/types/procmgr.d.ts +29 -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/runtime-install.d.ts +68 -0
- package/dist/types/sanitize-text.d.ts +29 -0
- package/dist/types/snowflake.d.ts +25 -0
- package/dist/types/stream.d.ts +68 -0
- package/dist/types/tab-spacing.d.ts +24 -0
- package/dist/types/temp.d.ts +17 -0
- package/dist/types/timing-buffer.d.ts +22 -0
- package/dist/types/tls-fetch.d.ts +37 -0
- package/dist/types/type-guards.d.ts +3 -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/which.d.ts +37 -0
- package/dist/types/worker-host.d.ts +47 -0
- package/package.json +62 -0
- package/src/abortable.ts +109 -0
- package/src/async.ts +50 -0
- package/src/binary.ts +50 -0
- package/src/cli.ts +457 -0
- package/src/color.ts +302 -0
- package/src/dirs.ts +925 -0
- package/src/env.ts +226 -0
- package/src/fetch-retry.ts +355 -0
- package/src/format.ts +113 -0
- package/src/frontmatter.ts +162 -0
- package/src/fs-error.ts +56 -0
- package/src/glob.ts +189 -0
- package/src/index.ts +55 -0
- package/src/json-parse.ts +612 -0
- package/src/json.ts +10 -0
- package/src/logger.ts +672 -0
- package/src/loop-phase.ts +49 -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 +222 -0
- package/src/procmgr.ts +195 -0
- package/src/prompt.ts +562 -0
- package/src/ptree.ts +395 -0
- package/src/ring.ts +169 -0
- package/src/runtime-install.ts +372 -0
- package/src/sanitize-text.ts +96 -0
- package/src/snowflake.ts +121 -0
- package/src/stream.ts +432 -0
- package/src/tab-spacing.ts +336 -0
- package/src/temp.ts +134 -0
- package/src/timing-buffer.ts +47 -0
- package/src/tls-fetch.ts +178 -0
- package/src/type-guards.ts +11 -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 +215 -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/which.ts +232 -0
- package/src/worker-host.ts +92 -0
|
@@ -0,0 +1,260 @@
|
|
|
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
|
+
/**
|
|
22
|
+
* Normalize and validate a profile name. Returns `undefined` for the implicit
|
|
23
|
+
* default (empty string, whitespace, or the explicit "default" sentinel) and
|
|
24
|
+
* throws for syntactically invalid or platform-reserved names.
|
|
25
|
+
*
|
|
26
|
+
* Exported so consumers of `@oh-my-pi-zen/pi-utils/dirs` (CLI bootstrap, tests,
|
|
27
|
+
* downstream tools) can validate user input without re-deriving the rules.
|
|
28
|
+
*/
|
|
29
|
+
export declare function normalizeProfileName(profile: string | undefined): string | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Resolve the active profile from the two profile env vars. `OMP_PROFILE` is the
|
|
32
|
+
* canonical variable and takes precedence; `PI_PROFILE` is the legacy
|
|
33
|
+
* compatibility fallback, consulted only when `OMP_PROFILE` is undefined. An
|
|
34
|
+
* explicitly-empty `OMP_PROFILE` therefore selects the default profile rather
|
|
35
|
+
* than silently inheriting `PI_PROFILE`. Delegates validation/normalization to
|
|
36
|
+
* {@link normalizeProfileName} (which throws on a syntactically invalid value).
|
|
37
|
+
*/
|
|
38
|
+
export declare function resolveProfileEnv(omp: string | undefined, pi: string | undefined): string | undefined;
|
|
39
|
+
export declare function resolveEquivalentPath(inputPath: string): string;
|
|
40
|
+
export declare function normalizePathForComparison(inputPath: string): string;
|
|
41
|
+
export declare function pathIsWithin(root: string, candidate: string): boolean;
|
|
42
|
+
export declare function relativePathWithinRoot(root: string, candidate: string): string | null;
|
|
43
|
+
/** Get the project directory. */
|
|
44
|
+
export declare function getProjectDir(): string;
|
|
45
|
+
/** Set the project directory. */
|
|
46
|
+
export declare function setProjectDir(dir: string): void;
|
|
47
|
+
/**
|
|
48
|
+
* Whether `dir` resolves to an existing directory. Any stat failure — a deleted
|
|
49
|
+
* path (ENOENT), permission error, or a non-directory — returns `false`, so
|
|
50
|
+
* callers can decide whether a directory is safe to `chdir` into or adopt as a
|
|
51
|
+
* working directory before {@link setProjectDir} throws on it.
|
|
52
|
+
*/
|
|
53
|
+
export declare function directoryExists(dir: string): Promise<boolean>;
|
|
54
|
+
/** Get the config directory name relative to home (e.g. ".omp" or PI_CONFIG_DIR override). */
|
|
55
|
+
export declare function getConfigDirName(): string;
|
|
56
|
+
/** Get the config agent directory name relative to home (e.g. ".omp/agent" or PI_CONFIG_DIR + "/agent"). */
|
|
57
|
+
export declare function getConfigAgentDirName(): string;
|
|
58
|
+
/**
|
|
59
|
+
* Rebuild the dirs resolver from the current environment, reusing the profile
|
|
60
|
+
* resolved at module load. Directory-affecting keys (XDG_*_HOME and, in default
|
|
61
|
+
* mode, `PI_CODING_AGENT_DIR`) loaded from a profile/agent `.env` only reach
|
|
62
|
+
* `process.env` *after* this module froze the resolver at import time, so
|
|
63
|
+
* `env.ts` calls this once after applying its `.env` files. The agent `.env`
|
|
64
|
+
* location derives from the profile name + home before this runs, so the
|
|
65
|
+
* rebuild re-reads only the directory vars, never the profile selection. The
|
|
66
|
+
* `preProfileAgentDirEnv` snapshot is intentionally left untouched.
|
|
67
|
+
*/
|
|
68
|
+
export declare function refreshDirsFromEnv(): void;
|
|
69
|
+
/** Get the config root directory (~/.omp). */
|
|
70
|
+
export declare function getConfigRootDir(): string;
|
|
71
|
+
/** Set the coding agent directory. Creates a fresh resolver, invalidating all cached paths. */
|
|
72
|
+
export declare function setAgentDir(dir: string): void;
|
|
73
|
+
/**
|
|
74
|
+
* Test-only: reset the pre-profile `PI_CODING_AGENT_DIR` snapshot to whatever
|
|
75
|
+
* the current environment looks like. Cross-suite test pollution can otherwise
|
|
76
|
+
* leak a stale snapshot through `setAgentDir` and corrupt `setProfile(undefined)`
|
|
77
|
+
* restore semantics. Production code MUST NOT call this — the snapshot's
|
|
78
|
+
* lifecycle is owned by `setAgentDir` / `setProfile` and a runtime caller has
|
|
79
|
+
* no business clearing it.
|
|
80
|
+
*/
|
|
81
|
+
export declare function __resetProfileSnapshotForTests(): void;
|
|
82
|
+
/**
|
|
83
|
+
* Test-only: rebuild profile + directory state from the current process env.
|
|
84
|
+
* Production code keeps the module-load profile stable; tests that mutate
|
|
85
|
+
* `setAgentDir`/`setProfile` need an exact restore point after they put env vars
|
|
86
|
+
* back.
|
|
87
|
+
*/
|
|
88
|
+
export declare function __resetDirsFromEnvForTests(): void;
|
|
89
|
+
/** Activate a named profile. Passing undefined or "default" returns to the default profile. */
|
|
90
|
+
export declare function setProfile(profile: string | undefined): void;
|
|
91
|
+
/** Get the active named profile. Undefined means the default profile. */
|
|
92
|
+
export declare function getActiveProfile(): string | undefined;
|
|
93
|
+
/** Resolve the config root that backs a profile without activating it. */
|
|
94
|
+
export declare function getProfileRootDir(profile: string | undefined): string;
|
|
95
|
+
/** Get the agent config directory (~/.omp/agent). */
|
|
96
|
+
export declare function getAgentDir(): string;
|
|
97
|
+
/** Get the project-local config directory (.omp). */
|
|
98
|
+
export declare function getProjectAgentDir(cwd?: string): string;
|
|
99
|
+
/** Get the reports directory (~/.omp/reports). */
|
|
100
|
+
export declare function getReportsDir(): string;
|
|
101
|
+
/** Get the logs directory (~/.omp/logs). */
|
|
102
|
+
export declare function getLogsDir(): string;
|
|
103
|
+
/** Get the path to a dated log file (~/.omp/logs/omp.YYYY-MM-DD.log). */
|
|
104
|
+
export declare function getLogPath(date?: Date): string;
|
|
105
|
+
/**
|
|
106
|
+
* Get the plugins directory (~/.omp/plugins or its XDG equivalent).
|
|
107
|
+
*
|
|
108
|
+
* No-arg form (production callers) goes through the XDG-aware DirResolver so
|
|
109
|
+
* reads and writes always agree. The optional `home` parameter is for test
|
|
110
|
+
* isolation: when it differs from `os.homedir()` it short-circuits the resolver
|
|
111
|
+
* and returns `<home>/<configDir>/plugins` so tests with a temp HOME get a
|
|
112
|
+
* deterministic path. Passing `os.homedir()` explicitly is identical to the
|
|
113
|
+
* no-arg form — XDG semantics are preserved.
|
|
114
|
+
*/
|
|
115
|
+
export declare function getPluginsDir(home?: string): string;
|
|
116
|
+
/** Where npm installs packages (~/.omp/plugins/node_modules). */
|
|
117
|
+
export declare function getPluginsNodeModules(home?: string): string;
|
|
118
|
+
/** Plugin manifest (~/.omp/plugins/package.json). */
|
|
119
|
+
export declare function getPluginsPackageJson(home?: string): string;
|
|
120
|
+
/** Plugin lock file (~/.omp/plugins/omp-plugins.lock.json). */
|
|
121
|
+
export declare function getPluginsLockfile(home?: string): string;
|
|
122
|
+
/** Get the remote mount directory (~/.omp/remote). */
|
|
123
|
+
export declare function getRemoteDir(): string;
|
|
124
|
+
/**
|
|
125
|
+
* Relocate the base directory for agent-managed worktrees (PR checkouts, task
|
|
126
|
+
* isolation, and `omp worktree` cleanup all read the same base). Driven by the
|
|
127
|
+
* `worktree.base` setting in coding-agent; pass `undefined`/empty to clear and
|
|
128
|
+
* fall back to `OMP_WORKTREE_DIR` or the `~/.omp/wt` default.
|
|
129
|
+
*
|
|
130
|
+
* `~` is expanded and a relative path is rejected (see {@link resolveWorktreeBase}).
|
|
131
|
+
* Returns the absolute path that took effect, or `undefined` if the input was
|
|
132
|
+
* cleared or rejected — callers can warn on a non-empty input that returns
|
|
133
|
+
* `undefined`.
|
|
134
|
+
*/
|
|
135
|
+
export declare function setWorktreesDir(dir: string | undefined): string | undefined;
|
|
136
|
+
/**
|
|
137
|
+
* Get the agent-managed worktrees directory. Resolution order: the
|
|
138
|
+
* `OMP_WORKTREE_DIR` env var, then the {@link setWorktreesDir} override (the
|
|
139
|
+
* `worktree.base` setting), then the `~/.omp/wt` default. The env var and the
|
|
140
|
+
* override are both `~`-expanded and must be absolute; a relative value is
|
|
141
|
+
* ignored and resolution falls through.
|
|
142
|
+
*/
|
|
143
|
+
export declare function getWorktreesDir(): string;
|
|
144
|
+
/** Get the SSH control socket directory (~/.omp/ssh-control). */
|
|
145
|
+
export declare function getSshControlDir(): string;
|
|
146
|
+
/** Get the remote host info directory (~/.omp/remote-host). */
|
|
147
|
+
export declare function getRemoteHostDir(): string;
|
|
148
|
+
/** Get the managed Python venv directory (~/.omp/python-env). */
|
|
149
|
+
export declare function getPythonEnvDir(): string;
|
|
150
|
+
/** Get the shared Python gateway state directory (~/.omp/agent/python-gateway; XDG default: $XDG_STATE_HOME/omp/python-gateway). */
|
|
151
|
+
export declare function getPythonGatewayDir(): string;
|
|
152
|
+
/** Get the puppeteer sandbox directory (~/.omp/puppeteer). */
|
|
153
|
+
export declare function getPuppeteerDir(): string;
|
|
154
|
+
/** Get DOCS_RS cache directory () */
|
|
155
|
+
export declare function getDocsRsCacheDir(): string;
|
|
156
|
+
/**Get AutoQa db directory */
|
|
157
|
+
export declare function getAutoQaDbDir(): string;
|
|
158
|
+
/**
|
|
159
|
+
* Stable 7-character hex digest of an absolute filesystem path.
|
|
160
|
+
*
|
|
161
|
+
* Used to pack the project identity into a single short fs-safe segment
|
|
162
|
+
* (e.g. PR-checkout and task-isolation worktree dirs under `~/.omp/wt/`).
|
|
163
|
+
* Bun.hash is non-cryptographic — collision space is ~2^28, which is fine
|
|
164
|
+
* for naming a handful of repos on a single machine. Same input on the
|
|
165
|
+
* same Bun runtime yields the same output.
|
|
166
|
+
*/
|
|
167
|
+
export declare function hashPath(absPath: string): string;
|
|
168
|
+
/** Get the path to a single worktree directory (~/.omp/wt/<segment>). */
|
|
169
|
+
export declare function getWorktreeDir(segment: string): string;
|
|
170
|
+
/** Get the GPU cache path (~/.omp/gpu_cache.json). */
|
|
171
|
+
export declare function getGpuCachePath(): string;
|
|
172
|
+
/**
|
|
173
|
+
* Get the GitHub view cache database path (~/.omp/cache/github-cache.db).
|
|
174
|
+
* Honors the `OMP_GITHUB_CACHE_DB` env var when set so tests can isolate the
|
|
175
|
+
* cache file without touching the rest of the config root.
|
|
176
|
+
*/
|
|
177
|
+
export declare function getGithubCacheDbPath(): string;
|
|
178
|
+
/**
|
|
179
|
+
* Get the encrypted auth-broker snapshot cache path (~/.omp/cache/auth-broker-snapshot.enc).
|
|
180
|
+
* Honors the `OMP_AUTH_BROKER_SNAPSHOT_CACHE` env var when set so tests and
|
|
181
|
+
* operators can isolate or relocate the cache file.
|
|
182
|
+
*/
|
|
183
|
+
export declare function getAuthBrokerSnapshotCachePath(): string;
|
|
184
|
+
/** Get the local FastEmbed model cache directory (~/.omp/cache/fastembed). */
|
|
185
|
+
export declare function getFastembedCacheDir(): string;
|
|
186
|
+
/** Get the on-demand fastembed runtime install root (~/.omp/cache/fastembed-runtime). */
|
|
187
|
+
export declare function getFastembedRuntimeDir(): string;
|
|
188
|
+
/** Get the natives directory (~/.omp/natives). */
|
|
189
|
+
export declare function getNativesDir(): string;
|
|
190
|
+
/** Get the stats database path (~/.omp/stats.db). */
|
|
191
|
+
export declare function getStatsDbPath(): string;
|
|
192
|
+
/** Get the autoresearch state directory (~/.omp/autoresearch). */
|
|
193
|
+
export declare function getAutoresearchDir(): string;
|
|
194
|
+
/** Get the per-project autoresearch state directory (~/.omp/autoresearch/<encoded-project>). */
|
|
195
|
+
export declare function getAutoresearchProjectDir(encodedProject: string): string;
|
|
196
|
+
/** Get the per-project autoresearch SQLite database path (~/.omp/autoresearch/<encoded-project>.db). */
|
|
197
|
+
export declare function getAutoresearchDbPath(encodedProject: string): string;
|
|
198
|
+
/** Get the per-run artifact directory (~/.omp/autoresearch/<encoded-project>/runs/<runId>). */
|
|
199
|
+
export declare function getAutoresearchRunDir(encodedProject: string, runId: number): string;
|
|
200
|
+
/** Get the path to agent.db (SQLite database for settings and auth storage). */
|
|
201
|
+
export declare function getAgentDbPath(agentDir?: string): string;
|
|
202
|
+
/** Get the last-seen-changelog-version marker file (~/.omp/agent/last-changelog-version). */
|
|
203
|
+
export declare function getLastChangelogVersionPath(agentDir?: string): string;
|
|
204
|
+
/** Get the path to history.db (SQLite database for session history). */
|
|
205
|
+
export declare function getHistoryDbPath(agentDir?: string): string;
|
|
206
|
+
/** Get the path to models.db (model cache database). */
|
|
207
|
+
export declare function getModelDbPath(agentDir?: string): string;
|
|
208
|
+
/** Get the tiny title model cache directory (~/.omp/agent/cache/tiny-models). */
|
|
209
|
+
export declare function getTinyModelsCacheDir(agentDir?: string): string;
|
|
210
|
+
/** Get the document conversion cache directory (~/.omp/agent/cache/document-conversions; XDG default: $XDG_CACHE_HOME/omp/cache/document-conversions). */
|
|
211
|
+
export declare function getDocumentConversionCacheDir(agentDir?: string): string;
|
|
212
|
+
/** Get the sessions directory (~/.omp/agent/sessions). */
|
|
213
|
+
export declare function getSessionsDir(agentDir?: string): string;
|
|
214
|
+
/** Get the content-addressed blob store directory (~/.omp/agent/blobs). */
|
|
215
|
+
export declare function getBlobsDir(agentDir?: string): string;
|
|
216
|
+
/** Get the custom themes directory (~/.omp/agent/themes). */
|
|
217
|
+
export declare function getCustomThemesDir(agentDir?: string): string;
|
|
218
|
+
/** Get the tools directory (~/.omp/agent/tools). */
|
|
219
|
+
export declare function getToolsDir(agentDir?: string): string;
|
|
220
|
+
/** Get the slash commands directory (~/.omp/agent/commands). */
|
|
221
|
+
export declare function getCommandsDir(agentDir?: string): string;
|
|
222
|
+
/** Get the prompts directory (~/.omp/agent/prompts). */
|
|
223
|
+
export declare function getPromptsDir(agentDir?: string): string;
|
|
224
|
+
/** Get the user-level Python modules directory (~/.omp/agent/modules). */
|
|
225
|
+
export declare function getAgentModulesDir(agentDir?: string): string;
|
|
226
|
+
/** Get the memories directory (~/.omp/agent/memories). */
|
|
227
|
+
export declare function getMemoriesDir(agentDir?: string): string;
|
|
228
|
+
/** Get the terminal sessions directory (~/.omp/agent/terminal-sessions). */
|
|
229
|
+
export declare function getTerminalSessionsDir(agentDir?: string): string;
|
|
230
|
+
/** Get the crash log path (~/.omp/agent/omp-crash.log). */
|
|
231
|
+
export declare function getCrashLogPath(agentDir?: string): string;
|
|
232
|
+
/** Get the debug log path (~/.omp/agent/omp-debug.log). */
|
|
233
|
+
export declare function getDebugLogPath(agentDir?: string): string;
|
|
234
|
+
/** Get the project-level Python modules directory (.omp/modules). */
|
|
235
|
+
export declare function getProjectModulesDir(cwd?: string): string;
|
|
236
|
+
/** Get the project-level prompts directory (.omp/prompts). */
|
|
237
|
+
export declare function getProjectPromptsDir(cwd?: string): string;
|
|
238
|
+
/** Get the project-level plugin overrides path (.omp/plugin-overrides.json). */
|
|
239
|
+
export declare function getProjectPluginOverridesPath(cwd?: string): string;
|
|
240
|
+
/** Get the primary MCP config file path (first candidate). */
|
|
241
|
+
export declare function getMCPConfigPath(scope: "user" | "project", cwd?: string): string;
|
|
242
|
+
/** Get the SSH config file path. */
|
|
243
|
+
export declare function getSSHConfigPath(scope: "user" | "project", cwd?: string): string;
|
|
244
|
+
/**
|
|
245
|
+
* Persistent per-install UUID stored at `~/.omp/install-id`.
|
|
246
|
+
*
|
|
247
|
+
* Generated lazily on first call and persisted with `O_CREAT|O_EXCL` so
|
|
248
|
+
* concurrent first-call races don't clobber each other (loser re-reads the
|
|
249
|
+
* winner's id). Survives independently of agent state: deleting
|
|
250
|
+
* `~/.omp/agent/` does not regenerate it. Server-side dedup for grievance
|
|
251
|
+
* pushes (and similar telemetry) keys on this id.
|
|
252
|
+
*
|
|
253
|
+
* Anchored to the base config root (`~/.omp/install-id`) regardless of the
|
|
254
|
+
* active profile: install identity is per-install, not per-profile, so every
|
|
255
|
+
* profile shares one id and the global cache stays correct no matter the
|
|
256
|
+
* profile / `getInstallId` call order.
|
|
257
|
+
*/
|
|
258
|
+
export declare function getInstallId(): string;
|
|
259
|
+
/** Test-only: clear cached install id. Never call from production code. */
|
|
260
|
+
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 "@oh-my-pi-zen/pi-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;
|
|
@@ -0,0 +1,94 @@
|
|
|
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 5 min` / `try again in ~158 min`
|
|
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
|
+
* Optional retry gate for HTTP responses whose status is retryable. Receives a
|
|
48
|
+
* cloned body string so callers can fail fast on deterministic provider
|
|
49
|
+
* failures that happen to use a 5xx status.
|
|
50
|
+
*/
|
|
51
|
+
shouldRetryResponse?: (response: Response, bodyText: string, attempt: number) => boolean | Promise<boolean>;
|
|
52
|
+
/**
|
|
53
|
+
* Bun extension forwarded verbatim to the underlying `fetch` call. `false`
|
|
54
|
+
* disables Bun's native ~300s pre-response timeout (callers that own a
|
|
55
|
+
* configurable first-event/idle watchdog or an external `AbortSignal`
|
|
56
|
+
* supply this so the runtime ceiling cannot pre-empt them); a positive
|
|
57
|
+
* number sets a custom ceiling in ms. Bare browser/Node fetch ignores it.
|
|
58
|
+
*/
|
|
59
|
+
timeout?: number | false;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Fetch with bounded retries and sensible defaults. Retries on any
|
|
63
|
+
* `isRetryableStatus` (5xx, 408, 429) and on transient network errors. Server
|
|
64
|
+
* `Retry-After`/quota hints are honoured up to `maxDelayMs`; a hint that exceeds
|
|
65
|
+
* the cap returns the current response so the caller can fail fast. Aborts on
|
|
66
|
+
* `init.signal` propagate as `"Request was aborted"`.
|
|
67
|
+
*
|
|
68
|
+
* The caller is responsible for inspecting `!response.ok` once the call returns.
|
|
69
|
+
*/
|
|
70
|
+
export declare function fetchWithRetry(url: string | URL | ((attempt: number) => string | URL), options?: FetchWithRetryOptions): Promise<Response>;
|
|
71
|
+
/**
|
|
72
|
+
* Inspect an arbitrary error value (or its `cause` chain, up to depth 2) for an
|
|
73
|
+
* HTTP status code. Reads `status`, `statusCode`, and `response.status` fields,
|
|
74
|
+
* coerces string values, and falls back to scanning the error message for
|
|
75
|
+
* common patterns like `Error: 401`, `error (429)`, or `HTTP 503`.
|
|
76
|
+
*/
|
|
77
|
+
export declare function extractHttpStatusFromError(error: unknown): number | undefined;
|
|
78
|
+
/**
|
|
79
|
+
* `true` if the given HTTP status code is one we treat as transient: 408
|
|
80
|
+
* (Request Timeout), 429 (Too Many Requests), or any 5xx (server error).
|
|
81
|
+
*/
|
|
82
|
+
export declare function isRetryableStatus(status: number): boolean;
|
|
83
|
+
/**
|
|
84
|
+
* `true` if the message describes an unexpected socket closure — Bun and some
|
|
85
|
+
* proxies surface these for any HTTP/2 stream reset.
|
|
86
|
+
*/
|
|
87
|
+
export declare function isUnexpectedSocketCloseMessage(message: string): boolean;
|
|
88
|
+
/**
|
|
89
|
+
* Identify errors that should be retried: aborts/timeouts in the error name or
|
|
90
|
+
* message, retryable HTTP statuses (see `isRetryableStatus`), unexpected socket
|
|
91
|
+
* closes, and the standard transient phrases. 4xx statuses other than 408/429
|
|
92
|
+
* and validation-shaped messages short-circuit to `false`.
|
|
93
|
+
*/
|
|
94
|
+
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-zen/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-zen/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,35 @@
|
|
|
1
|
+
export { once, untilAborted } from "./abortable";
|
|
2
|
+
export * from "./async";
|
|
3
|
+
export * from "./binary";
|
|
4
|
+
export * from "./color";
|
|
5
|
+
export * from "./dirs";
|
|
6
|
+
export * from "./env";
|
|
7
|
+
export * from "./fetch-retry";
|
|
8
|
+
export * from "./format";
|
|
9
|
+
export * from "./frontmatter";
|
|
10
|
+
export * from "./fs-error";
|
|
11
|
+
export * from "./glob";
|
|
12
|
+
export * from "./json";
|
|
13
|
+
export * from "./json-parse";
|
|
14
|
+
export * as logger from "./logger";
|
|
15
|
+
export * from "./loop-phase";
|
|
16
|
+
export * from "./mermaid-ascii";
|
|
17
|
+
export * from "./mime";
|
|
18
|
+
export * from "./path";
|
|
19
|
+
export * from "./path-tree";
|
|
20
|
+
export * from "./peek-file";
|
|
21
|
+
export * as postmortem from "./postmortem";
|
|
22
|
+
export * as procmgr from "./procmgr";
|
|
23
|
+
export * as prompt from "./prompt";
|
|
24
|
+
export * as ptree from "./ptree";
|
|
25
|
+
export { AbortError, ChildProcess, Exception, NonZeroExitError } from "./ptree";
|
|
26
|
+
export * from "./runtime-install";
|
|
27
|
+
export * from "./sanitize-text";
|
|
28
|
+
export * from "./snowflake";
|
|
29
|
+
export * from "./stream";
|
|
30
|
+
export * from "./tab-spacing";
|
|
31
|
+
export * from "./temp";
|
|
32
|
+
export * from "./tls-fetch";
|
|
33
|
+
export * from "./type-guards";
|
|
34
|
+
export * from "./which";
|
|
35
|
+
export declare function structuredCloneJSON<T>(value: T): T;
|
|
@@ -0,0 +1,48 @@
|
|
|
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;
|