metheus-governance-mcp-cli 0.2.224 → 0.2.225

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 (2) hide show
  1. package/cli.mjs +29 -2
  2. package/package.json +1 -1
package/cli.mjs CHANGED
@@ -2061,6 +2061,34 @@ function loadBotRunnerState() {
2061
2061
  }
2062
2062
  }
2063
2063
 
2064
+ function writeTextFileAtomic(filePath, text) {
2065
+ const normalizedPath = String(filePath || "").trim();
2066
+ if (!normalizedPath) {
2067
+ throw new Error("filePath is required");
2068
+ }
2069
+ const directoryPath = path.dirname(normalizedPath);
2070
+ fs.mkdirSync(directoryPath, { recursive: true });
2071
+ const tempPath = path.join(
2072
+ directoryPath,
2073
+ `.${path.basename(normalizedPath)}.${process.pid}.${Date.now()}.tmp`,
2074
+ );
2075
+ fs.writeFileSync(tempPath, text, "utf8");
2076
+ try {
2077
+ fs.renameSync(tempPath, normalizedPath);
2078
+ } catch (error) {
2079
+ try {
2080
+ fs.rmSync(normalizedPath, { force: true });
2081
+ } catch {}
2082
+ fs.renameSync(tempPath, normalizedPath);
2083
+ } finally {
2084
+ try {
2085
+ if (fs.existsSync(tempPath)) {
2086
+ fs.rmSync(tempPath, { force: true });
2087
+ }
2088
+ } catch {}
2089
+ }
2090
+ }
2091
+
2064
2092
  function saveBotRunnerState(nextState) {
2065
2093
  const filePath = botRunnerStateFilePath();
2066
2094
  let current = {};
@@ -2238,8 +2266,7 @@ function saveBotRunnerState(nextState) {
2238
2266
  nextState?.consumedComments ?? nextState?.consumed_comments ?? current.consumed_comments ?? current.consumedComments,
2239
2267
  ),
2240
2268
  };
2241
- fs.mkdirSync(path.dirname(filePath), { recursive: true });
2242
- fs.writeFileSync(filePath, `${JSON.stringify(payload, null, 2)}\n`, "utf8");
2269
+ writeTextFileAtomic(filePath, `${JSON.stringify(payload, null, 2)}\n`);
2243
2270
  return filePath;
2244
2271
  }
2245
2272
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "metheus-governance-mcp-cli",
3
- "version": "0.2.224",
3
+ "version": "0.2.225",
4
4
  "description": "Metheus Governance MCP CLI (setup + stdio proxy)",
5
5
  "type": "module",
6
6
  "files": [