@gendigital/sage-openclaw 0.4.2 → 0.4.4
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.cjs +71 -14
- package/dist/index.cjs.map +2 -2
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -7348,9 +7348,36 @@ function getFileContentRaw(path) {
|
|
|
7348
7348
|
async function atomicWriteJson(path, data) {
|
|
7349
7349
|
await fsPromises.mkdir((0, import_node_path.dirname)(path), { recursive: true });
|
|
7350
7350
|
const tmp = `${path}.${(0, import_node_crypto.randomBytes)(6).toString("hex")}.tmp`;
|
|
7351
|
-
|
|
7351
|
+
try {
|
|
7352
|
+
await fsPromises.writeFile(tmp, `${JSON.stringify(data, null, 2)}
|
|
7352
7353
|
`, { mode: 384 });
|
|
7353
|
-
|
|
7354
|
+
await fsPromises.rename(tmp, path);
|
|
7355
|
+
} catch (err) {
|
|
7356
|
+
try {
|
|
7357
|
+
await fsPromises.unlink(tmp);
|
|
7358
|
+
} catch {
|
|
7359
|
+
}
|
|
7360
|
+
throw err;
|
|
7361
|
+
}
|
|
7362
|
+
}
|
|
7363
|
+
async function pruneOrphanedTmpFiles(resolvedDir, maxAgeMs = 3e5) {
|
|
7364
|
+
try {
|
|
7365
|
+
const entries = await fsPromises.readdir(resolvedDir);
|
|
7366
|
+
const now = Date.now();
|
|
7367
|
+
for (const entry of entries) {
|
|
7368
|
+
if (!entry.endsWith(".tmp"))
|
|
7369
|
+
continue;
|
|
7370
|
+
try {
|
|
7371
|
+
const fullPath = (0, import_node_path.join)(resolvedDir, entry);
|
|
7372
|
+
const s = await fsPromises.stat(fullPath);
|
|
7373
|
+
if (now - s.mtimeMs > maxAgeMs) {
|
|
7374
|
+
await fsPromises.unlink(fullPath);
|
|
7375
|
+
}
|
|
7376
|
+
} catch {
|
|
7377
|
+
}
|
|
7378
|
+
}
|
|
7379
|
+
} catch {
|
|
7380
|
+
}
|
|
7354
7381
|
}
|
|
7355
7382
|
|
|
7356
7383
|
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/external.js
|
|
@@ -11445,7 +11472,9 @@ var AllowlistConfigSchema = external_exports.object({
|
|
|
11445
11472
|
var LoggingConfigSchema = external_exports.object({
|
|
11446
11473
|
enabled: external_exports.boolean().default(true),
|
|
11447
11474
|
log_clean: external_exports.boolean().default(false),
|
|
11448
|
-
path: external_exports.string().default("~/.sage/audit.jsonl")
|
|
11475
|
+
path: external_exports.string().default("~/.sage/audit.jsonl"),
|
|
11476
|
+
max_bytes: external_exports.number().int().min(0).default(5 * 1024 * 1024),
|
|
11477
|
+
max_files: external_exports.number().int().min(0).default(3)
|
|
11449
11478
|
});
|
|
11450
11479
|
var FileCheckConfigSchema = external_exports.object({
|
|
11451
11480
|
endpoint: external_exports.string().optional(),
|
|
@@ -11623,6 +11652,40 @@ function toolInputSummary(toolName, toolInput) {
|
|
|
11623
11652
|
}
|
|
11624
11653
|
return JSON.stringify(toolInput).slice(0, MAX_SUMMARY_LEN);
|
|
11625
11654
|
}
|
|
11655
|
+
async function rotateIfNeeded(filePath, maxBytes, maxFiles) {
|
|
11656
|
+
if (maxBytes <= 0 || maxFiles <= 0)
|
|
11657
|
+
return;
|
|
11658
|
+
let size;
|
|
11659
|
+
try {
|
|
11660
|
+
const s = await (0, import_promises.stat)(filePath);
|
|
11661
|
+
size = s.size;
|
|
11662
|
+
} catch {
|
|
11663
|
+
return;
|
|
11664
|
+
}
|
|
11665
|
+
if (size < maxBytes)
|
|
11666
|
+
return;
|
|
11667
|
+
try {
|
|
11668
|
+
await (0, import_promises.unlink)(`${filePath}.${maxFiles}`);
|
|
11669
|
+
} catch {
|
|
11670
|
+
}
|
|
11671
|
+
for (let i = maxFiles - 1; i >= 1; i--) {
|
|
11672
|
+
try {
|
|
11673
|
+
await (0, import_promises.rename)(`${filePath}.${i}`, `${filePath}.${i + 1}`);
|
|
11674
|
+
} catch {
|
|
11675
|
+
}
|
|
11676
|
+
}
|
|
11677
|
+
try {
|
|
11678
|
+
await (0, import_promises.rename)(filePath, `${filePath}.1`);
|
|
11679
|
+
} catch {
|
|
11680
|
+
}
|
|
11681
|
+
}
|
|
11682
|
+
async function appendEntry(config, entry) {
|
|
11683
|
+
const path = resolvePath(config.path);
|
|
11684
|
+
await (0, import_promises.mkdir)((0, import_node_path4.dirname)(path), { recursive: true });
|
|
11685
|
+
await rotateIfNeeded(path, config.max_bytes, config.max_files);
|
|
11686
|
+
await (0, import_promises.appendFile)(path, `${JSON.stringify(entry)}
|
|
11687
|
+
`);
|
|
11688
|
+
}
|
|
11626
11689
|
async function logVerdict(config, sessionId, toolName, toolInput, verdict, userOverride = false) {
|
|
11627
11690
|
if (!config.enabled)
|
|
11628
11691
|
return;
|
|
@@ -11641,11 +11704,8 @@ async function logVerdict(config, sessionId, toolName, toolInput, verdict, userO
|
|
|
11641
11704
|
source: verdict.source,
|
|
11642
11705
|
user_override: userOverride
|
|
11643
11706
|
};
|
|
11644
|
-
const path = resolvePath(config.path);
|
|
11645
11707
|
try {
|
|
11646
|
-
await (
|
|
11647
|
-
await (0, import_promises.appendFile)(path, `${JSON.stringify(entry)}
|
|
11648
|
-
`);
|
|
11708
|
+
await appendEntry(config, entry);
|
|
11649
11709
|
} catch {
|
|
11650
11710
|
}
|
|
11651
11711
|
}
|
|
@@ -11660,11 +11720,8 @@ async function logPluginScan(config, pluginKey, pluginVersion, findings) {
|
|
|
11660
11720
|
findings_count: findings.length,
|
|
11661
11721
|
findings
|
|
11662
11722
|
};
|
|
11663
|
-
const path = resolvePath(config.path);
|
|
11664
11723
|
try {
|
|
11665
|
-
await (
|
|
11666
|
-
await (0, import_promises.appendFile)(path, `${JSON.stringify(entry)}
|
|
11667
|
-
`);
|
|
11724
|
+
await appendEntry(config, entry);
|
|
11668
11725
|
} catch {
|
|
11669
11726
|
}
|
|
11670
11727
|
}
|
|
@@ -11808,7 +11865,7 @@ var VerdictCache = class {
|
|
|
11808
11865
|
};
|
|
11809
11866
|
|
|
11810
11867
|
// ../core/dist/version.js
|
|
11811
|
-
var VERSION = true ? "0.4.
|
|
11868
|
+
var VERSION = true ? "0.4.4" : "dev";
|
|
11812
11869
|
|
|
11813
11870
|
// ../core/dist/clients/file-check.js
|
|
11814
11871
|
var DEFAULT_TIMEOUT = 5;
|
|
@@ -12683,7 +12740,6 @@ async function loadScanCache(configHash = "", cachePath = DEFAULT_CACHE_PATH, lo
|
|
|
12683
12740
|
}
|
|
12684
12741
|
async function saveScanCache(cache, cachePath = DEFAULT_CACHE_PATH, logger = nullLogger) {
|
|
12685
12742
|
try {
|
|
12686
|
-
await (0, import_promises4.mkdir)((0, import_node_path7.dirname)(cachePath), { recursive: true });
|
|
12687
12743
|
const data = {
|
|
12688
12744
|
config_hash: cache.configHash,
|
|
12689
12745
|
entries: Object.fromEntries(Object.entries(cache.entries).map(([key, entry]) => [
|
|
@@ -12696,7 +12752,7 @@ async function saveScanCache(cache, cachePath = DEFAULT_CACHE_PATH, logger = nul
|
|
|
12696
12752
|
}
|
|
12697
12753
|
]))
|
|
12698
12754
|
};
|
|
12699
|
-
await (
|
|
12755
|
+
await atomicWriteJson(cachePath, data);
|
|
12700
12756
|
} catch (e) {
|
|
12701
12757
|
logger.warn(`Failed to save scan cache to ${cachePath}`, { error: String(e) });
|
|
12702
12758
|
}
|
|
@@ -13186,6 +13242,7 @@ async function discoverOpenClawPlugins(logger, extensionsDir = DEFAULT_EXTENSION
|
|
|
13186
13242
|
// src/startup-scan.ts
|
|
13187
13243
|
var SAGE_PLUGIN_ID = "sage-openclaw";
|
|
13188
13244
|
async function runScan(logger, context) {
|
|
13245
|
+
await pruneOrphanedTmpFiles(resolvePath("~/.sage"));
|
|
13189
13246
|
const { threatsDir, allowlistsDir } = getBundledDataDirs();
|
|
13190
13247
|
const version = getSageVersion();
|
|
13191
13248
|
logger.info(`Sage plugin scan started (${context})`, { threatsDir, allowlistsDir });
|