mono-pilot 0.2.6 → 0.2.7
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.
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import { existsSync } from "node:fs";
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
2
|
import { readdir } from "node:fs/promises";
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
|
-
import { join, resolve } from "node:path";
|
|
4
|
+
import { dirname, join, resolve } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
5
6
|
import { Text } from "@mariozechner/pi-tui";
|
|
6
7
|
import { hasMessageEntries } from "./mode-runtime.js";
|
|
7
8
|
const SESSION_HINTS_MESSAGE_TYPE = "SessionHints";
|
|
8
9
|
const RULES_RELATIVE_DIR = join(".pi", "rules");
|
|
10
|
+
const MONO_PILOT_NAME = "mono-pilot";
|
|
11
|
+
const MAX_VERSION_SEARCH_DEPTH = 6;
|
|
12
|
+
let cachedVersion = null;
|
|
9
13
|
/** List *.rule.txt full paths from a directory (empty array if dir missing). */
|
|
10
14
|
async function listRuleFiles(dirPath) {
|
|
11
15
|
if (!existsSync(dirPath))
|
|
@@ -38,11 +42,46 @@ function shortenHome(filePath) {
|
|
|
38
42
|
}
|
|
39
43
|
return filePath;
|
|
40
44
|
}
|
|
45
|
+
function findPackageJsonPath() {
|
|
46
|
+
let currentDir = dirname(fileURLToPath(import.meta.url));
|
|
47
|
+
for (let depth = 0; depth < MAX_VERSION_SEARCH_DEPTH; depth += 1) {
|
|
48
|
+
const candidate = resolve(currentDir, "package.json");
|
|
49
|
+
if (existsSync(candidate))
|
|
50
|
+
return candidate;
|
|
51
|
+
const parentDir = dirname(currentDir);
|
|
52
|
+
if (parentDir === currentDir)
|
|
53
|
+
break;
|
|
54
|
+
currentDir = parentDir;
|
|
55
|
+
}
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
function getMonoPilotVersion() {
|
|
59
|
+
if (cachedVersion !== null)
|
|
60
|
+
return cachedVersion || undefined;
|
|
61
|
+
try {
|
|
62
|
+
const packageJsonPath = findPackageJsonPath();
|
|
63
|
+
if (!packageJsonPath) {
|
|
64
|
+
cachedVersion = "";
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
const raw = readFileSync(packageJsonPath, "utf8");
|
|
68
|
+
const parsed = JSON.parse(raw);
|
|
69
|
+
cachedVersion = typeof parsed.version === "string" ? parsed.version : "";
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
cachedVersion = "";
|
|
73
|
+
}
|
|
74
|
+
return cachedVersion || undefined;
|
|
75
|
+
}
|
|
41
76
|
export default function sessionHintsExtension(pi) {
|
|
42
77
|
// Render hints matching pi's native section style (same colors as [Context], [Skills], etc.)
|
|
43
78
|
pi.registerMessageRenderer(SESSION_HINTS_MESSAGE_TYPE, (message, _options, theme) => {
|
|
44
79
|
const details = message.details;
|
|
45
80
|
const lines = [];
|
|
81
|
+
const version = getMonoPilotVersion();
|
|
82
|
+
const versionLabel = version ? ` v${version}` : "";
|
|
83
|
+
lines.push(theme.bold(theme.fg("accent", MONO_PILOT_NAME)) + theme.fg("dim", versionLabel));
|
|
84
|
+
lines.push("");
|
|
46
85
|
const userRules = details?.userRules ?? [];
|
|
47
86
|
const projectRules = details?.projectRules ?? [];
|
|
48
87
|
if (userRules.length > 0 || projectRules.length > 0) {
|