@oh-my-pi/pi-utils 12.1.0 → 12.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/package.json +16 -11
  2. package/src/dirs.ts +25 -5
  3. package/src/glob.ts +5 -4
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@oh-my-pi/pi-utils",
3
- "version": "12.1.0",
3
+ "version": "12.2.0",
4
4
  "description": "Shared utilities for pi packages",
5
+ "keywords": ["utilities", "cli", "logging", "streams"],
5
6
  "type": "module",
6
7
  "main": "./src/index.ts",
7
8
  "types": "./src/index.ts",
@@ -34,14 +35,18 @@
34
35
  "url": "git+https://github.com/can1357/oh-my-pi.git",
35
36
  "directory": "packages/utils"
36
37
  },
37
- "dependencies": {
38
- "winston": "^3.19.0",
39
- "winston-daily-rotate-file": "^5.0.0"
40
- },
41
- "devDependencies": {
42
- "@types/bun": "^1.3.9"
43
- },
44
- "engines": {
45
- "bun": ">=1.3.7"
46
- }
38
+ "homepage": "https://github.com/can1357/oh-my-pi",
39
+ "bugs": {
40
+ "url": "https://github.com/can1357/oh-my-pi/issues"
41
+ },
42
+ "dependencies": {
43
+ "winston": "^3.19.0",
44
+ "winston-daily-rotate-file": "^5.0.0"
45
+ },
46
+ "devDependencies": {
47
+ "@types/bun": "^1.3.9"
48
+ },
49
+ "engines": {
50
+ "bun": ">=1.3.7"
51
+ }
47
52
  }
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 = process.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 = process.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 = process.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 = process.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 = process.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 process.cwd(). */
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 process.cwd()).
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 ?? process.cwd());
144
+ const gitignorePatterns = await loadGitignorePatterns(cwd ?? getProjectDir());
144
145
  effectiveExclude = [...effectiveExclude, ...gitignorePatterns];
145
146
  }
146
147
 
147
- const base = cwd ?? process.cwd();
148
+ const base = cwd ?? getProjectDir();
148
149
  const allResults: string[] = [];
149
150
 
150
151
  // Combine timeout and abort signals