@oh-my-pi/pi-utils 12.10.1 → 12.11.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.
- package/package.json +1 -1
- package/src/dirs.ts +8 -4
- package/src/env.ts +19 -1
package/package.json
CHANGED
package/src/dirs.ts
CHANGED
|
@@ -9,7 +9,6 @@ import * as fs from "node:fs";
|
|
|
9
9
|
import * as os from "node:os";
|
|
10
10
|
import * as path from "node:path";
|
|
11
11
|
import { version } from "../package.json" with { type: "json" };
|
|
12
|
-
import { $env } from "./env";
|
|
13
12
|
|
|
14
13
|
/** App name (e.g. "omp") */
|
|
15
14
|
export const APP_NAME: string = "omp";
|
|
@@ -54,16 +53,16 @@ export function setProjectDir(dir: string): void {
|
|
|
54
53
|
|
|
55
54
|
/** Get the config root directory (~/.omp). */
|
|
56
55
|
export function getConfigRootDir(): string {
|
|
57
|
-
return path.join(os.homedir(),
|
|
56
|
+
return path.join(os.homedir(), process.env.PI_CONFIG_DIR || CONFIG_DIR_NAME);
|
|
58
57
|
}
|
|
59
58
|
|
|
60
|
-
let agentDir =
|
|
59
|
+
let agentDir = process.env.PI_CODING_AGENT_DIR || path.join(getConfigRootDir(), "agent");
|
|
61
60
|
|
|
62
61
|
/** Set the coding agent directory. */
|
|
63
62
|
export function setAgentDir(dir: string): void {
|
|
64
63
|
agentDir = dir;
|
|
65
64
|
agentCache.clear();
|
|
66
|
-
|
|
65
|
+
process.env.PI_CODING_AGENT_DIR = dir;
|
|
67
66
|
}
|
|
68
67
|
|
|
69
68
|
/** Get the agent config directory (~/.omp/agent). */
|
|
@@ -166,6 +165,11 @@ export function getPythonEnvDir(): string {
|
|
|
166
165
|
return getRootSubdir("python-env");
|
|
167
166
|
}
|
|
168
167
|
|
|
168
|
+
/** Get the puppeteer sandbox directory (~/.omp/puppeteer). */
|
|
169
|
+
export function getPuppeteerDir(): string {
|
|
170
|
+
return getRootSubdir("puppeteer");
|
|
171
|
+
}
|
|
172
|
+
|
|
169
173
|
/** Get the worktree base directory (~/.omp/wt). */
|
|
170
174
|
export function getWorktreeBaseDir(): string {
|
|
171
175
|
return getRootSubdir("wt");
|
package/src/env.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as fs from "node:fs";
|
|
2
2
|
import * as os from "node:os";
|
|
3
3
|
import * as path from "node:path";
|
|
4
|
+
import { getAgentDir, getConfigRootDir } from "./dirs";
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Parses a .env file synchronously and extracts key-value string pairs.
|
|
@@ -46,9 +47,11 @@ function parseEnvFile(filePath: string): Record<string, string> {
|
|
|
46
47
|
|
|
47
48
|
// Eagerly parse the user's $HOME/.env and the current project's .env (from cwd)
|
|
48
49
|
const homeEnv = parseEnvFile(path.join(os.homedir(), ".env"));
|
|
50
|
+
const piEnv = parseEnvFile(path.join(getConfigRootDir(), ".env"));
|
|
51
|
+
const agentEnv = parseEnvFile(path.join(getAgentDir(), ".env"));
|
|
49
52
|
const projectEnv = parseEnvFile(path.join(process.cwd(), ".env"));
|
|
50
53
|
|
|
51
|
-
for (const file of [projectEnv, homeEnv]) {
|
|
54
|
+
for (const file of [projectEnv, agentEnv, piEnv, homeEnv]) {
|
|
52
55
|
for (const [key, value] of Object.entries(file)) {
|
|
53
56
|
if (!Bun.env[key]) {
|
|
54
57
|
Bun.env[key] = value;
|
|
@@ -64,3 +67,18 @@ for (const file of [projectEnv, homeEnv]) {
|
|
|
64
67
|
* overrides (project, home) have been applied, so $env always reflects the correct values.
|
|
65
68
|
*/
|
|
66
69
|
export const $env: Record<string, string> = Bun.env as Record<string, string>;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Resolve the first environment variable value from the given keys.
|
|
73
|
+
* @param keys - The keys to resolve.
|
|
74
|
+
* @returns The first environment variable value, or undefined if no value is found.
|
|
75
|
+
*/
|
|
76
|
+
export function $pickenv(...keys: string[]): string | undefined {
|
|
77
|
+
for (const key of keys) {
|
|
78
|
+
const value = Bun.env[key]?.trim();
|
|
79
|
+
if (value) {
|
|
80
|
+
return value;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|