The folder automation re-admitted a file every minute when the user had removed its jobs while a hoster was still missing, because nothing recorded the removal. Removing automatic jobs (selected, all, per hoster or through MCP) now stores the file path and identity in automation-dismissals.json. The automation skips such files until the file changes or the user adds it manually again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
13178512bf
commit
f64fe23019
8 files changed
+176
-11
No files matched your search
@@ -211,6 +211,56 @@
|
||||
});
|
||||
}
|
||||
|
||||
function normalizeAutomationDismissal(value) {
|
||||
const row = asObject(value);
|
||||
const path = String(row.path || '').trim();
|
||||
const fileIdentity = typeof row.fileIdentity === 'string' ? row.fileIdentity.trim() : '';
|
||||
const dismissedAt = Number(row.dismissedAt);
|
||||
if (!path || !fileIdentity) return null;
|
||||
return { path, fileIdentity, dismissedAt: Number.isFinite(dismissedAt) && dismissedAt >= 0 ? Math.trunc(dismissedAt) : 0 };
|
||||
}
|
||||
|
||||
function mergeAutomationDismissals(existing, incoming, maxEntries = 5000) {
|
||||
const merged = new Map();
|
||||
for (const source of [asArray(existing), asArray(incoming)]) {
|
||||
for (const value of source) {
|
||||
const row = normalizeAutomationDismissal(value);
|
||||
if (!row) continue;
|
||||
const key = normalizePath(row.path);
|
||||
merged.delete(key);
|
||||
merged.set(key, row);
|
||||
}
|
||||
}
|
||||
const limit = Number.isFinite(Number(maxEntries)) ? Math.max(1, Math.floor(Number(maxEntries))) : 5000;
|
||||
const rows = [...merged.values()];
|
||||
return rows.slice(Math.max(0, rows.length - limit));
|
||||
}
|
||||
|
||||
function removeAutomationDismissals(existing, paths) {
|
||||
const removed = new Set(asArray(paths).map(normalizePath).filter(Boolean));
|
||||
return mergeAutomationDismissals(existing, []).filter(row => !removed.has(normalizePath(row.path)));
|
||||
}
|
||||
|
||||
function automationDismissalsForRemovedJobs(jobs, now = Date.now()) {
|
||||
return mergeAutomationDismissals([], asArray(jobs)
|
||||
.filter(job => job && job.automationAdmission === true && job.status !== 'done')
|
||||
.map(job => ({ path: job.file, fileIdentity: job.sourceFileIdentity, dismissedAt: now })));
|
||||
}
|
||||
|
||||
function classifyAutomationDismissals(input = {}) {
|
||||
const value = asObject(input);
|
||||
const rows = new Map(mergeAutomationDismissals(value.dismissals, []).map(row => [normalizePath(row.path), row]));
|
||||
const dismissedPaths = [];
|
||||
const stalePaths = [];
|
||||
for (const candidate of asArray(value.candidates)) {
|
||||
const row = rows.get(normalizePath(candidate?.path));
|
||||
if (!row || typeof candidate.fileIdentity !== 'string' || !candidate.fileIdentity) continue;
|
||||
if (candidate.fileIdentity === row.fileIdentity) dismissedPaths.push(candidate.path);
|
||||
else stalePaths.push(row.path);
|
||||
}
|
||||
return { dismissedPaths, stalePaths };
|
||||
}
|
||||
|
||||
function classifyAutomationCompletionLedger(input = {}) {
|
||||
const value = asObject(input);
|
||||
const rows = new Map();
|
||||
@@ -341,6 +391,11 @@
|
||||
createAutomationCompletionWriter,
|
||||
normalizeAutomationCompletion,
|
||||
mergeAutomationCompletions,
|
||||
removeAutomationCompletions
|
||||
removeAutomationCompletions,
|
||||
normalizeAutomationDismissal,
|
||||
mergeAutomationDismissals,
|
||||
removeAutomationDismissals,
|
||||
automationDismissalsForRemovedJobs,
|
||||
classifyAutomationDismissals
|
||||
};
|
||||
});
|
||||
+50
-1
@@ -2,7 +2,7 @@ const fs = require('fs');
|
||||
const path = require('path');
|
||||
const secretStore = require('./secret-store');
|
||||
const { normalizeLogMode } = require('./log-mode');
|
||||
const { mergeAutomationCompletions, normalizeAutomationCompletion, removeAutomationCompletions } = require('./automation-control');
|
||||
const { mergeAutomationCompletions, normalizeAutomationCompletion, removeAutomationCompletions, mergeAutomationDismissals, removeAutomationDismissals } = require('./automation-control');
|
||||
|
||||
const TRANSIENT_RENAME_ERROR_CODES = new Set(['EPERM', 'EBUSY', 'EACCES']);
|
||||
const RENAME_RETRY_DELAYS_MS = [50, 100, 200, 400, 800, 1600, 3200];
|
||||
@@ -188,6 +188,9 @@ class ConfigStore {
|
||||
this.filePath = path.join(dir, 'electron-config.json');
|
||||
this.historyPath = path.join(dir, 'electron-history.json');
|
||||
this.automationCompletionPath = path.join(dir, 'automation-completions.json');
|
||||
this.automationDismissalPath = path.join(dir, 'automation-dismissals.json');
|
||||
this._automationDismissalWriteQueue = Promise.resolve();
|
||||
this._automationDismissalCache = null;
|
||||
this._writeQueue = Promise.resolve(); // Serializes all writes to prevent race conditions
|
||||
this._historyWriteQueue = Promise.resolve();
|
||||
this._automationCompletionWriteQueue = Promise.resolve();
|
||||
@@ -768,6 +771,52 @@ class ConfigStore {
|
||||
await this._automationCompletionWriteQueue;
|
||||
}
|
||||
|
||||
async _readAutomationDismissalFile() {
|
||||
try {
|
||||
const parsed = JSON.parse(await fs.promises.readFile(this.automationDismissalPath, 'utf8'));
|
||||
return mergeAutomationDismissals([], parsed && parsed.entries);
|
||||
} catch (error) {
|
||||
if (error?.code === 'ENOENT') return [];
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async _writeAutomationDismissalFile(entries) {
|
||||
const target = this.automationDismissalPath;
|
||||
const temporary = `${target}.tmp`;
|
||||
await fs.promises.mkdir(path.dirname(target), { recursive: true });
|
||||
await fs.promises.writeFile(temporary, JSON.stringify({ version: 1, entries }), 'utf8');
|
||||
await this._renameWithRetry(temporary, target);
|
||||
}
|
||||
|
||||
_updateAutomationDismissals(update) {
|
||||
const result = this._automationDismissalWriteQueue.then(async () => {
|
||||
const current = this._automationDismissalCache || await this._readAutomationDismissalFile();
|
||||
const next = update(current);
|
||||
await this._writeAutomationDismissalFile(next);
|
||||
this._automationDismissalCache = next;
|
||||
return this._clone(next);
|
||||
});
|
||||
this._automationDismissalWriteQueue = result.catch(() => {});
|
||||
return result;
|
||||
}
|
||||
|
||||
async loadAutomationDismissals() {
|
||||
await this._automationDismissalWriteQueue;
|
||||
if (!this._automationDismissalCache) this._automationDismissalCache = await this._readAutomationDismissalFile();
|
||||
return this._clone(this._automationDismissalCache);
|
||||
}
|
||||
|
||||
addAutomationDismissals(entries) {
|
||||
const incoming = this._clone(Array.isArray(entries) ? entries : []);
|
||||
return this._updateAutomationDismissals(current => mergeAutomationDismissals(current, incoming));
|
||||
}
|
||||
|
||||
removeAutomationDismissals(paths) {
|
||||
const removed = Array.isArray(paths) ? paths.map(String) : [];
|
||||
return this._updateAutomationDismissals(current => removeAutomationDismissals(current, removed));
|
||||
}
|
||||
|
||||
saveLastBrowseDirectory(directory) {
|
||||
const snapshot = String(directory || '').trim();
|
||||
return this._enqueueWrite(async () => {
|
||||
|
||||
Reference in new issue
Block a user