@mtreeai/msapling-cli 2.3.6-beta.2 → 2.3.6-beta.3
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/dist/index.js +44 -17
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -7016,12 +7016,15 @@ var init_Storage = __esm({
|
|
|
7016
7016
|
* This ensures:
|
|
7017
7017
|
* 1. Only one process writes at a time (file lock)
|
|
7018
7018
|
* 2. Partial writes don't corrupt the JSON (atomic rename)
|
|
7019
|
+
*
|
|
7020
|
+
* CLI-LSTAT-HISTORY-01: Pass realpath:false so lockfile never calls lstat on a
|
|
7021
|
+
* path that may not exist yet (first run before any history has been written).
|
|
7019
7022
|
*/
|
|
7020
7023
|
async saveHistory(history) {
|
|
7021
7024
|
const path2 = join14(this.baseDir, "history", "shell_history.json");
|
|
7022
7025
|
let release2;
|
|
7023
7026
|
try {
|
|
7024
|
-
release2 = await lockfile.lock(path2, { retries: 5, retryWait: 50 });
|
|
7027
|
+
release2 = await lockfile.lock(path2, { retries: 5, retryWait: 50, realpath: false });
|
|
7025
7028
|
await this.historyMutex.run(async () => {
|
|
7026
7029
|
const tmpPath = `${path2}.tmp`;
|
|
7027
7030
|
const content = JSON.stringify(history, null, 2);
|
|
@@ -7042,7 +7045,7 @@ var init_Storage = __esm({
|
|
|
7042
7045
|
} finally {
|
|
7043
7046
|
if (release2) {
|
|
7044
7047
|
try {
|
|
7045
|
-
await lockfile.unlock(path2, { skipStale: true });
|
|
7048
|
+
await lockfile.unlock(path2, { skipStale: true, realpath: false });
|
|
7046
7049
|
} catch (e) {
|
|
7047
7050
|
console.warn(`Failed to unlock history file: ${e}`);
|
|
7048
7051
|
}
|
|
@@ -7053,23 +7056,41 @@ var init_Storage = __esm({
|
|
|
7053
7056
|
* SYNC-01: Serialised history read with file-based locking.
|
|
7054
7057
|
* Reads are gated behind the file lock so a read that overlaps with an
|
|
7055
7058
|
* in-progress write from another process always sees a complete, valid JSON.
|
|
7059
|
+
*
|
|
7060
|
+
* CLI-LSTAT-HISTORY-01: Short-circuit before locking when the file is absent
|
|
7061
|
+
* so lockfile never calls lstat/realpath on a nonexistent path (ENOENT crash
|
|
7062
|
+
* on fresh install). Corrupt JSON is caught, backed up, and treated as empty
|
|
7063
|
+
* rather than propagating a parse error.
|
|
7056
7064
|
*/
|
|
7057
7065
|
async loadHistory() {
|
|
7058
7066
|
const path2 = join14(this.baseDir, "history", "shell_history.json");
|
|
7067
|
+
if (!existsSync13(path2)) {
|
|
7068
|
+
return [];
|
|
7069
|
+
}
|
|
7059
7070
|
let release2;
|
|
7060
7071
|
try {
|
|
7061
|
-
release2 = await lockfile.lock(path2, { retries: 5, retryWait: 50 });
|
|
7062
|
-
return this.historyMutex.run(async () => {
|
|
7063
|
-
if (existsSync13(path2)) {
|
|
7064
|
-
|
|
7072
|
+
release2 = await lockfile.lock(path2, { retries: 5, retryWait: 50, realpath: false });
|
|
7073
|
+
return await this.historyMutex.run(async () => {
|
|
7074
|
+
if (!existsSync13(path2)) {
|
|
7075
|
+
return [];
|
|
7076
|
+
}
|
|
7077
|
+
const text = await readFile12(path2, "utf8");
|
|
7078
|
+
try {
|
|
7065
7079
|
return JSON.parse(text);
|
|
7080
|
+
} catch {
|
|
7081
|
+
console.warn("[msapling] shell_history.json is corrupt; resetting to empty history.");
|
|
7082
|
+
const backupPath = `${path2}.corrupt.${Date.now()}.bak`;
|
|
7083
|
+
try {
|
|
7084
|
+
renameSync2(path2, backupPath);
|
|
7085
|
+
} catch {
|
|
7086
|
+
}
|
|
7087
|
+
return [];
|
|
7066
7088
|
}
|
|
7067
|
-
return [];
|
|
7068
7089
|
});
|
|
7069
7090
|
} finally {
|
|
7070
7091
|
if (release2) {
|
|
7071
7092
|
try {
|
|
7072
|
-
await lockfile.unlock(path2, { skipStale: true });
|
|
7093
|
+
await lockfile.unlock(path2, { skipStale: true, realpath: false });
|
|
7073
7094
|
} catch (e) {
|
|
7074
7095
|
console.warn(`Failed to unlock history file: ${e}`);
|
|
7075
7096
|
}
|
|
@@ -7078,12 +7099,13 @@ var init_Storage = __esm({
|
|
|
7078
7099
|
}
|
|
7079
7100
|
/**
|
|
7080
7101
|
* SYNC-01: Serialised permissions write with file-based locking.
|
|
7102
|
+
* CLI-LSTAT-HISTORY-01: realpath:false prevents ENOENT lstat on first run.
|
|
7081
7103
|
*/
|
|
7082
7104
|
async savePermissions(permissions) {
|
|
7083
7105
|
const path2 = join14(this.baseDir, "vault", "permissions.json");
|
|
7084
7106
|
let release2;
|
|
7085
7107
|
try {
|
|
7086
|
-
release2 = await lockfile.lock(path2, { retries: 5, retryWait: 50 });
|
|
7108
|
+
release2 = await lockfile.lock(path2, { retries: 5, retryWait: 50, realpath: false });
|
|
7087
7109
|
await this.permissionsMutex.run(async () => {
|
|
7088
7110
|
const tmpPath = `${path2}.tmp`;
|
|
7089
7111
|
const content = JSON.stringify(permissions, null, 2);
|
|
@@ -7104,7 +7126,7 @@ var init_Storage = __esm({
|
|
|
7104
7126
|
} finally {
|
|
7105
7127
|
if (release2) {
|
|
7106
7128
|
try {
|
|
7107
|
-
await lockfile.unlock(path2, { skipStale: true });
|
|
7129
|
+
await lockfile.unlock(path2, { skipStale: true, realpath: false });
|
|
7108
7130
|
} catch (e) {
|
|
7109
7131
|
console.warn(`Failed to unlock permissions file: ${e}`);
|
|
7110
7132
|
}
|
|
@@ -7113,23 +7135,28 @@ var init_Storage = __esm({
|
|
|
7113
7135
|
}
|
|
7114
7136
|
/**
|
|
7115
7137
|
* SYNC-01: Serialised permissions read with file-based locking.
|
|
7138
|
+
* CLI-LSTAT-HISTORY-01: Short-circuit on missing file; realpath:false avoids
|
|
7139
|
+
* lstat on a path that may not exist yet on a fresh install.
|
|
7116
7140
|
*/
|
|
7117
7141
|
async loadPermissions() {
|
|
7118
7142
|
const path2 = join14(this.baseDir, "vault", "permissions.json");
|
|
7143
|
+
if (!existsSync13(path2)) {
|
|
7144
|
+
return { trustedCommands: [], trustedPaths: [] };
|
|
7145
|
+
}
|
|
7119
7146
|
let release2;
|
|
7120
7147
|
try {
|
|
7121
|
-
release2 = await lockfile.lock(path2, { retries: 5, retryWait: 50 });
|
|
7122
|
-
return this.permissionsMutex.run(async () => {
|
|
7123
|
-
if (existsSync13(path2)) {
|
|
7124
|
-
|
|
7125
|
-
return JSON.parse(text);
|
|
7148
|
+
release2 = await lockfile.lock(path2, { retries: 5, retryWait: 50, realpath: false });
|
|
7149
|
+
return await this.permissionsMutex.run(async () => {
|
|
7150
|
+
if (!existsSync13(path2)) {
|
|
7151
|
+
return { trustedCommands: [], trustedPaths: [] };
|
|
7126
7152
|
}
|
|
7127
|
-
|
|
7153
|
+
const text = await readFile12(path2, "utf8");
|
|
7154
|
+
return JSON.parse(text);
|
|
7128
7155
|
});
|
|
7129
7156
|
} finally {
|
|
7130
7157
|
if (release2) {
|
|
7131
7158
|
try {
|
|
7132
|
-
await lockfile.unlock(path2, { skipStale: true });
|
|
7159
|
+
await lockfile.unlock(path2, { skipStale: true, realpath: false });
|
|
7133
7160
|
} catch (e) {
|
|
7134
7161
|
console.warn(`Failed to unlock permissions file: ${e}`);
|
|
7135
7162
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mtreeai/msapling-cli",
|
|
3
|
-
"version": "2.3.6-beta.
|
|
3
|
+
"version": "2.3.6-beta.3",
|
|
4
4
|
"description": "MSapling CLI — React/Ink terminal client for the MSapling backend (chat, projects, MDrive, agent tools). Proprietary, see LICENSE.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"author": "MSapling Team",
|