mono-pilot 0.2.4 → 0.2.5

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,5 +1,6 @@
1
1
  import { existsSync } from "node:fs";
2
2
  import { readdir, readFile } from "node:fs/promises";
3
+ import { homedir } from "node:os";
3
4
  import { dirname, join, resolve } from "node:path";
4
5
  import process from "node:process";
5
6
  import { fileURLToPath, pathToFileURL } from "node:url";
@@ -138,37 +139,48 @@ async function buildMcpInstructionsEnvelope(workspaceCwd) {
138
139
  }
139
140
  async function buildRulesEnvelope(workspaceCwd) {
140
141
  const rulesDirPath = resolve(workspaceCwd, RULES_RELATIVE_DIR);
141
- if (!existsSync(rulesDirPath))
142
- return undefined;
143
- let directoryEntries;
144
- try {
145
- directoryEntries = await readdir(rulesDirPath, { withFileTypes: true, encoding: "utf8" });
146
- }
147
- catch {
148
- return undefined;
149
- }
150
- const ruleFileNames = directoryEntries
151
- .filter((entry) => entry.isFile() && entry.name.endsWith(".rule.txt"))
152
- .map((entry) => entry.name)
153
- .sort((a, b) => a.localeCompare(b));
154
- if (ruleFileNames.length === 0)
155
- return undefined;
156
- const rules = [];
157
- for (const ruleFileName of ruleFileNames) {
158
- const ruleFilePath = resolve(rulesDirPath, ruleFileName);
142
+ const userRulesDirPath = resolve(homedir(), RULES_RELATIVE_DIR);
143
+ const loadRulesFromDir = async (dirPath) => {
144
+ if (!existsSync(dirPath))
145
+ return new Map();
146
+ let directoryEntries;
159
147
  try {
160
- const content = await readFile(ruleFilePath, "utf-8");
161
- const normalized = content.trim();
162
- if (normalized.length > 0) {
163
- rules.push(normalized);
164
- }
148
+ directoryEntries = await readdir(dirPath, { withFileTypes: true, encoding: "utf8" });
165
149
  }
166
150
  catch {
167
- // Ignore unreadable rule files.
151
+ return new Map();
152
+ }
153
+ const ruleFileNames = directoryEntries
154
+ .filter((entry) => entry.isFile() && entry.name.endsWith(".rule.txt"))
155
+ .map((entry) => entry.name)
156
+ .sort((a, b) => a.localeCompare(b));
157
+ const rules = new Map();
158
+ for (const ruleFileName of ruleFileNames) {
159
+ const ruleFilePath = resolve(dirPath, ruleFileName);
160
+ try {
161
+ const content = await readFile(ruleFilePath, "utf-8");
162
+ const normalized = content.trim();
163
+ if (normalized.length > 0) {
164
+ rules.set(ruleFileName, normalized);
165
+ }
166
+ }
167
+ catch {
168
+ // Ignore unreadable rule files.
169
+ }
168
170
  }
171
+ return rules;
172
+ };
173
+ const userRules = await loadRulesFromDir(userRulesDirPath);
174
+ const workspaceRules = await loadRulesFromDir(rulesDirPath);
175
+ const mergedRules = new Map(userRules);
176
+ for (const [fileName, content] of workspaceRules) {
177
+ mergedRules.set(fileName, content);
169
178
  }
170
- if (rules.length === 0)
179
+ if (mergedRules.size === 0)
171
180
  return undefined;
181
+ const rules = Array.from(mergedRules.entries())
182
+ .sort(([a], [b]) => a.localeCompare(b))
183
+ .map(([, content]) => content);
172
184
  const lines = ["<rules>"];
173
185
  for (const rule of rules) {
174
186
  lines.push("<user_rule>");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mono-pilot",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "description": "Cursor-compatible coding agent powered by pi-mono",
5
5
  "type": "module",
6
6
  "license": "MIT",