@oh-my-pi/pi-utils 12.1.1 → 12.2.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/package.json +1 -1
- package/src/dirs.ts +25 -5
- package/src/glob.ts +5 -4
package/package.json
CHANGED
package/src/dirs.ts
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
* Uses PI_CONFIG_DIR (default ".omp") for the config root and
|
|
5
5
|
* PI_CODING_AGENT_DIR to override the agent directory.
|
|
6
6
|
*/
|
|
7
|
+
|
|
8
|
+
import { realpathSync } from "node:fs";
|
|
7
9
|
import * as os from "node:os";
|
|
8
10
|
import * as path from "node:path";
|
|
9
11
|
import { version } from "../package.json" with { type: "json" };
|
|
@@ -22,6 +24,24 @@ export const VERSION: string = version;
|
|
|
22
24
|
// Root directories
|
|
23
25
|
// =============================================================================
|
|
24
26
|
|
|
27
|
+
let projectDir = process.cwd();
|
|
28
|
+
if ($env.PWD) {
|
|
29
|
+
if (realpathSync($env.PWD) === projectDir) {
|
|
30
|
+
projectDir = $env.PWD;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Get the project directory. */
|
|
35
|
+
export function getProjectDir(): string {
|
|
36
|
+
return projectDir;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Set the project directory. */
|
|
40
|
+
export function setProjectDir(dir: string): void {
|
|
41
|
+
projectDir = path.resolve(dir);
|
|
42
|
+
process.chdir(projectDir);
|
|
43
|
+
}
|
|
44
|
+
|
|
25
45
|
/** Get the config root directory (~/.omp). */
|
|
26
46
|
export function getConfigRootDir(): string {
|
|
27
47
|
return path.join(os.homedir(), $env.PI_CONFIG_DIR || CONFIG_DIR_NAME);
|
|
@@ -42,7 +62,7 @@ export function getAgentDir(): string {
|
|
|
42
62
|
}
|
|
43
63
|
|
|
44
64
|
/** Get the project-local config directory (.omp). */
|
|
45
|
-
export function getProjectAgentDir(cwd: string =
|
|
65
|
+
export function getProjectAgentDir(cwd: string = getProjectDir()): string {
|
|
46
66
|
return path.join(cwd, CONFIG_DIR_NAME);
|
|
47
67
|
}
|
|
48
68
|
|
|
@@ -225,17 +245,17 @@ export function getDebugLogPath(agentDir?: string): string {
|
|
|
225
245
|
// =============================================================================
|
|
226
246
|
|
|
227
247
|
/** Get the project-level Python modules directory (.omp/modules). */
|
|
228
|
-
export function getProjectModulesDir(cwd: string =
|
|
248
|
+
export function getProjectModulesDir(cwd: string = getProjectDir()): string {
|
|
229
249
|
return path.join(getProjectAgentDir(cwd), "modules");
|
|
230
250
|
}
|
|
231
251
|
|
|
232
252
|
/** Get the project-level prompts directory (.omp/prompts). */
|
|
233
|
-
export function getProjectPromptsDir(cwd: string =
|
|
253
|
+
export function getProjectPromptsDir(cwd: string = getProjectDir()): string {
|
|
234
254
|
return path.join(getProjectAgentDir(cwd), "prompts");
|
|
235
255
|
}
|
|
236
256
|
|
|
237
257
|
/** Get the project-level plugin overrides path (.omp/plugin-overrides.json). */
|
|
238
|
-
export function getProjectPluginOverridesPath(cwd: string =
|
|
258
|
+
export function getProjectPluginOverridesPath(cwd: string = getProjectDir()): string {
|
|
239
259
|
return path.join(getProjectAgentDir(cwd), "plugin-overrides.json");
|
|
240
260
|
}
|
|
241
261
|
|
|
@@ -244,7 +264,7 @@ export function getProjectPluginOverridesPath(cwd: string = process.cwd()): stri
|
|
|
244
264
|
// =============================================================================
|
|
245
265
|
|
|
246
266
|
/** Get the primary MCP config file path (first candidate). */
|
|
247
|
-
export function getMCPConfigPath(scope: "user" | "project", cwd: string =
|
|
267
|
+
export function getMCPConfigPath(scope: "user" | "project", cwd: string = getProjectDir()): string {
|
|
248
268
|
if (scope === "user") {
|
|
249
269
|
return path.join(getAgentDir(), "mcp.json");
|
|
250
270
|
}
|
package/src/glob.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import * as path from "node:path";
|
|
2
2
|
import { Glob } from "bun";
|
|
3
|
+
import { getProjectDir } from "./dirs";
|
|
3
4
|
|
|
4
5
|
export interface GlobPathsOptions {
|
|
5
|
-
/** Base directory for glob patterns. Defaults to
|
|
6
|
+
/** Base directory for glob patterns. Defaults to getProjectDir(). */
|
|
6
7
|
cwd?: string;
|
|
7
8
|
/** Glob exclusion patterns. */
|
|
8
9
|
exclude?: string[];
|
|
@@ -126,7 +127,7 @@ export async function loadGitignorePatterns(baseDir: string): Promise<string[]>
|
|
|
126
127
|
|
|
127
128
|
/**
|
|
128
129
|
* Resolve filesystem paths matching glob patterns with optional exclude filters.
|
|
129
|
-
* Returns paths relative to the provided cwd (or
|
|
130
|
+
* Returns paths relative to the provided cwd (or getProjectDir()).
|
|
130
131
|
* Errors and abort/timeouts are surfaced to the caller.
|
|
131
132
|
*/
|
|
132
133
|
export async function globPaths(patterns: string | string[], options: GlobPathsOptions = {}): Promise<string[]> {
|
|
@@ -140,11 +141,11 @@ export async function globPaths(patterns: string | string[], options: GlobPathsO
|
|
|
140
141
|
let effectiveExclude = exclude ? [...baseExclude, ...exclude] : baseExclude;
|
|
141
142
|
|
|
142
143
|
if (gitignore) {
|
|
143
|
-
const gitignorePatterns = await loadGitignorePatterns(cwd ??
|
|
144
|
+
const gitignorePatterns = await loadGitignorePatterns(cwd ?? getProjectDir());
|
|
144
145
|
effectiveExclude = [...effectiveExclude, ...gitignorePatterns];
|
|
145
146
|
}
|
|
146
147
|
|
|
147
|
-
const base = cwd ??
|
|
148
|
+
const base = cwd ?? getProjectDir();
|
|
148
149
|
const allResults: string[] = [];
|
|
149
150
|
|
|
150
151
|
// Combine timeout and abort signals
|