@oh-my-pi/pi-utils 12.0.0 → 12.1.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 +5 -1
- package/src/dirs.ts +252 -0
- package/src/logger.ts +1 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oh-my-pi/pi-utils",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.1.0",
|
|
4
4
|
"description": "Shared utilities for pi packages",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -13,6 +13,10 @@
|
|
|
13
13
|
"./cli": {
|
|
14
14
|
"types": "./src/cli.ts",
|
|
15
15
|
"import": "./src/cli.ts"
|
|
16
|
+
},
|
|
17
|
+
"./dirs": {
|
|
18
|
+
"types": "./src/dirs.ts",
|
|
19
|
+
"import": "./src/dirs.ts"
|
|
16
20
|
}
|
|
17
21
|
},
|
|
18
22
|
"files": [
|
package/src/dirs.ts
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
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
|
+
import * as os from "node:os";
|
|
8
|
+
import * as path from "node:path";
|
|
9
|
+
import { version } from "../package.json" with { type: "json" };
|
|
10
|
+
import { $env } from "./env";
|
|
11
|
+
|
|
12
|
+
/** App name (e.g. "omp") */
|
|
13
|
+
export const APP_NAME: string = "omp";
|
|
14
|
+
|
|
15
|
+
/** Config directory name (e.g. ".omp") */
|
|
16
|
+
export const CONFIG_DIR_NAME: string = ".omp";
|
|
17
|
+
|
|
18
|
+
/** Version (e.g. "1.0.0") */
|
|
19
|
+
export const VERSION: string = version;
|
|
20
|
+
|
|
21
|
+
// =============================================================================
|
|
22
|
+
// Root directories
|
|
23
|
+
// =============================================================================
|
|
24
|
+
|
|
25
|
+
/** Get the config root directory (~/.omp). */
|
|
26
|
+
export function getConfigRootDir(): string {
|
|
27
|
+
return path.join(os.homedir(), $env.PI_CONFIG_DIR || CONFIG_DIR_NAME);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
let agentDir = $env.PI_CODING_AGENT_DIR || path.join(getConfigRootDir(), "agent");
|
|
31
|
+
|
|
32
|
+
/** Set the coding agent directory. */
|
|
33
|
+
export function setAgentDir(dir: string): void {
|
|
34
|
+
agentDir = dir;
|
|
35
|
+
agentCache.clear();
|
|
36
|
+
$env.PI_CODING_AGENT_DIR = dir;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Get the agent config directory (~/.omp/agent). */
|
|
40
|
+
export function getAgentDir(): string {
|
|
41
|
+
return agentDir;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Get the project-local config directory (.omp). */
|
|
45
|
+
export function getProjectAgentDir(cwd: string = process.cwd()): string {
|
|
46
|
+
return path.join(cwd, CONFIG_DIR_NAME);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// =============================================================================
|
|
50
|
+
// Caching utilities
|
|
51
|
+
// =============================================================================
|
|
52
|
+
|
|
53
|
+
const rootCache = new Map<string, any>();
|
|
54
|
+
|
|
55
|
+
function getRootSubdir(subdir: string): string {
|
|
56
|
+
if (rootCache.has(subdir)) {
|
|
57
|
+
return rootCache.get(subdir);
|
|
58
|
+
}
|
|
59
|
+
const result = path.join(getConfigRootDir(), subdir);
|
|
60
|
+
rootCache.set(subdir, result);
|
|
61
|
+
return result;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const agentCache = new Map<string, any>();
|
|
65
|
+
|
|
66
|
+
function getAgentSubdir(userAgentDir: string | undefined, subdir: string): string {
|
|
67
|
+
if (!userAgentDir || userAgentDir === agentDir) {
|
|
68
|
+
if (agentCache.has(subdir)) {
|
|
69
|
+
return agentCache.get(subdir);
|
|
70
|
+
} else {
|
|
71
|
+
const result = path.join(agentDir, subdir);
|
|
72
|
+
agentCache.set(subdir, result);
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
} else {
|
|
76
|
+
return path.join(userAgentDir, subdir);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// =============================================================================
|
|
81
|
+
// Config-root subdirectories (~/.omp/*)
|
|
82
|
+
// =============================================================================
|
|
83
|
+
|
|
84
|
+
/** Get the reports directory (~/.omp/reports). */
|
|
85
|
+
export function getReportsDir(): string {
|
|
86
|
+
return getRootSubdir("reports");
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Get the logs directory (~/.omp/logs). */
|
|
90
|
+
export function getLogsDir(): string {
|
|
91
|
+
return getRootSubdir("logs");
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Get the path to a dated log file (~/.omp/logs/omp.YYYY-MM-DD.log). */
|
|
95
|
+
export function getLogPath(date = new Date()): string {
|
|
96
|
+
return path.join(getLogsDir(), `${APP_NAME}.${date.toISOString().slice(0, 10)}.log`);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Get the plugins directory (~/.omp/plugins). */
|
|
100
|
+
export function getPluginsDir(): string {
|
|
101
|
+
return getRootSubdir("plugins");
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Where npm installs packages (~/.omp/plugins/node_modules). */
|
|
105
|
+
export function getPluginsNodeModules(): string {
|
|
106
|
+
return getRootSubdir("plugins/node_modules");
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Plugin manifest (~/.omp/plugins/package.json). */
|
|
110
|
+
export function getPluginsPackageJson(): string {
|
|
111
|
+
return getRootSubdir("plugins/package.json");
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Plugin lock file (~/.omp/plugins/omp-plugins.lock.json). */
|
|
115
|
+
export function getPluginsLockfile(): string {
|
|
116
|
+
return getRootSubdir("plugins/omp-plugins.lock.json");
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Get the remote mount directory (~/.omp/remote). */
|
|
120
|
+
export function getRemoteDir(): string {
|
|
121
|
+
return getRootSubdir("remote");
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Get the SSH control socket directory (~/.omp/ssh-control). */
|
|
125
|
+
export function getSshControlDir(): string {
|
|
126
|
+
return getRootSubdir("ssh-control");
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** Get the remote host info directory (~/.omp/remote-host). */
|
|
130
|
+
export function getRemoteHostDir(): string {
|
|
131
|
+
return getRootSubdir("remote-host");
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Get the managed Python venv directory (~/.omp/python-env). */
|
|
135
|
+
export function getPythonEnvDir(): string {
|
|
136
|
+
return getRootSubdir("python-env");
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** Get the worktree base directory (~/.omp/wt). */
|
|
140
|
+
export function getWorktreeBaseDir(): string {
|
|
141
|
+
return getRootSubdir("wt");
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Get the path to a worktree directory (~/.omp/wt/<project>/<id>). */
|
|
145
|
+
export function getWorktreeDir(encodedProject: string, id: string): string {
|
|
146
|
+
return path.join(getWorktreeBaseDir(), encodedProject, id);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** Get the GPU cache path (~/.omp/gpu_cache.json). */
|
|
150
|
+
export function getGpuCachePath(): string {
|
|
151
|
+
return getRootSubdir("gpu_cache.json");
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** Get the natives directory (~/.omp/natives). */
|
|
155
|
+
export function getNativesDir(): string {
|
|
156
|
+
return getRootSubdir("natives");
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** Get the stats database path (~/.omp/stats.db). */
|
|
160
|
+
export function getStatsDbPath(): string {
|
|
161
|
+
return getRootSubdir("stats.db");
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// =============================================================================
|
|
165
|
+
// Agent subdirectories (~/.omp/agent/*)
|
|
166
|
+
// =============================================================================
|
|
167
|
+
|
|
168
|
+
/** Get the path to agent.db (SQLite database for settings and auth storage). */
|
|
169
|
+
export function getAgentDbPath(agentDir?: string): string {
|
|
170
|
+
return getAgentSubdir(agentDir, "agent.db");
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** Get the sessions directory (~/.omp/agent/sessions). */
|
|
174
|
+
export function getSessionsDir(agentDir?: string): string {
|
|
175
|
+
return getAgentSubdir(agentDir, "sessions");
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** Get the content-addressed blob store directory (~/.omp/agent/blobs). */
|
|
179
|
+
export function getBlobsDir(agentDir?: string): string {
|
|
180
|
+
return getAgentSubdir(agentDir, "blobs");
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** Get the custom themes directory (~/.omp/agent/themes). */
|
|
184
|
+
export function getCustomThemesDir(agentDir?: string): string {
|
|
185
|
+
return getAgentSubdir(agentDir, "themes");
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** Get the tools directory (~/.omp/agent/tools). */
|
|
189
|
+
export function getToolsDir(agentDir?: string): string {
|
|
190
|
+
return getAgentSubdir(agentDir, "tools");
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** Get the slash commands directory (~/.omp/agent/commands). */
|
|
194
|
+
export function getCommandsDir(agentDir?: string): string {
|
|
195
|
+
return getAgentSubdir(agentDir, "commands");
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** Get the prompts directory (~/.omp/agent/prompts). */
|
|
199
|
+
export function getPromptsDir(agentDir?: string): string {
|
|
200
|
+
return getAgentSubdir(agentDir, "prompts");
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** Get the user-level Python modules directory (~/.omp/agent/modules). */
|
|
204
|
+
export function getAgentModulesDir(agentDir?: string): string {
|
|
205
|
+
return getAgentSubdir(agentDir, "modules");
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** Get the test auth database path (~/.omp/agent/testauth.db). */
|
|
209
|
+
export function getTestAuthPath(agentDir?: string): string {
|
|
210
|
+
return getAgentSubdir(agentDir, "testauth.db");
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/** Get the crash log path (~/.omp/agent/omp-crash.log). */
|
|
214
|
+
export function getCrashLogPath(agentDir?: string): string {
|
|
215
|
+
return getAgentSubdir(agentDir, "omp-crash.log");
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** Get the debug log path (~/.omp/agent/omp-debug.log). */
|
|
219
|
+
export function getDebugLogPath(agentDir?: string): string {
|
|
220
|
+
return getAgentSubdir(agentDir, `${APP_NAME}-debug.log`);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// =============================================================================
|
|
224
|
+
// Project subdirectories (.omp/*)
|
|
225
|
+
// =============================================================================
|
|
226
|
+
|
|
227
|
+
/** Get the project-level Python modules directory (.omp/modules). */
|
|
228
|
+
export function getProjectModulesDir(cwd: string = process.cwd()): string {
|
|
229
|
+
return path.join(getProjectAgentDir(cwd), "modules");
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/** Get the project-level prompts directory (.omp/prompts). */
|
|
233
|
+
export function getProjectPromptsDir(cwd: string = process.cwd()): string {
|
|
234
|
+
return path.join(getProjectAgentDir(cwd), "prompts");
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/** Get the project-level plugin overrides path (.omp/plugin-overrides.json). */
|
|
238
|
+
export function getProjectPluginOverridesPath(cwd: string = process.cwd()): string {
|
|
239
|
+
return path.join(getProjectAgentDir(cwd), "plugin-overrides.json");
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// =============================================================================
|
|
243
|
+
// MCP config paths
|
|
244
|
+
// =============================================================================
|
|
245
|
+
|
|
246
|
+
/** Get the primary MCP config file path (first candidate). */
|
|
247
|
+
export function getMCPConfigPath(scope: "user" | "project", cwd: string = process.cwd()): string {
|
|
248
|
+
if (scope === "user") {
|
|
249
|
+
return path.join(getAgentDir(), "mcp.json");
|
|
250
|
+
}
|
|
251
|
+
return path.join(getProjectAgentDir(cwd), "mcp.json");
|
|
252
|
+
}
|
package/src/logger.ts
CHANGED
|
@@ -5,15 +5,9 @@
|
|
|
5
5
|
* Each log entry includes process.pid for traceability.
|
|
6
6
|
*/
|
|
7
7
|
import * as fs from "node:fs";
|
|
8
|
-
import * as os from "node:os";
|
|
9
|
-
import * as path from "node:path";
|
|
10
8
|
import winston from "winston";
|
|
11
9
|
import DailyRotateFile from "winston-daily-rotate-file";
|
|
12
|
-
|
|
13
|
-
/** Get the logs directory (~/.omp/logs/) */
|
|
14
|
-
function getLogsDir(): string {
|
|
15
|
-
return path.join(os.homedir(), ".omp", "logs");
|
|
16
|
-
}
|
|
10
|
+
import { getLogsDir } from "./dirs";
|
|
17
11
|
|
|
18
12
|
/** Ensure logs directory exists */
|
|
19
13
|
function ensureLogsDir(): string {
|