aibridge-context 1.4.0 → 1.4.1

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.
@@ -17,6 +17,36 @@ const LOW_VALUE_FEATURE_KEYS = new Set([
17
17
  'project_workflow'
18
18
  ]);
19
19
 
20
+ async function safeWriteJSON(filePath, data) {
21
+ const fs = require("fs");
22
+ const path = require("path");
23
+
24
+ const tmpPath = filePath + ".tmp";
25
+
26
+ try {
27
+ // ensure directory exists
28
+ fs.mkdirSync(path.dirname(filePath), { recursive: true });
29
+
30
+ // write temp file
31
+ await fs.promises.writeFile(tmpPath, data, "utf-8");
32
+
33
+ // rename only if tmp exists
34
+ if (fs.existsSync(tmpPath)) {
35
+ await fs.promises.rename(tmpPath, filePath);
36
+ } else {
37
+ await fs.promises.writeFile(filePath, data, "utf-8");
38
+ }
39
+ } catch (err) {
40
+ console.error("[aibridge] Write fallback triggered:", err.message);
41
+
42
+ try {
43
+ await fs.promises.writeFile(filePath, data, "utf-8");
44
+ } catch (e) {
45
+ console.error("[aibridge] Failed to write state file:", e.message);
46
+ }
47
+ }
48
+ }
49
+
20
50
  const FEATURE_CATALOG = {
21
51
  cli_workflow: {
22
52
  name: 'CLI workflow for initializing, updating, and linking AI context',
@@ -300,9 +330,7 @@ async function writeJsonAtomic(filePath, value) {
300
330
  }
301
331
 
302
332
  async function writeTextAtomic(filePath, content) {
303
- const tempFilePath = `${filePath}.tmp`;
304
- await fsp.writeFile(tempFilePath, content, 'utf8');
305
- await fsp.rename(tempFilePath, filePath);
333
+ await safeWriteJSON(filePath, content);
306
334
  }
307
335
 
308
336
  function createDefaultState(projectRoot) {
@@ -1449,4 +1477,4 @@ module.exports = {
1449
1477
  updateProjectState,
1450
1478
  writeJsonAtomic,
1451
1479
  writeTextAtomic
1452
- };
1480
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aibridge-context",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
4
4
  "description": "Zero-config CLI and library for generating AI-readable project context, serving it locally, and syncing it with git.",
5
5
  "main": "./index.js",
6
6
  "bin": {