This commit is contained in:
1 parent
d3cba015b5
commit
c4439480bd
6 files changed
+224
-17
No files matched your search
+42
-7
@@ -1,9 +1,11 @@
|
||||
const { randomUUID } = require('node:crypto');
|
||||
const path = require('node:path');
|
||||
const { McpAccessError, resolveGrantedFile } = require('./mcp-access');
|
||||
const { createMcpFiles } = require('./mcp-files');
|
||||
const { createMcpTransfers } = require('./mcp-transfers');
|
||||
const { createMcpDiagnostics } = require('./mcp-diagnostics');
|
||||
const { createMcpSanitizer } = require('./mcp-security');
|
||||
const { MCP_TOOLS, requiresMcpConfirmation } = require('./mcp-tools');
|
||||
const { redactLogText, collectSecretValues } = require('./support-bundle');
|
||||
|
||||
function page(items, args) {
|
||||
@@ -13,7 +15,7 @@ function page(items, args) {
|
||||
}
|
||||
|
||||
function createMcpApp({ loadConfig, invoke, invokeGuarded = (_context, channel, ...args) => invoke(channel, ...args), renderer, collectors, getGrants, trashFile, canWrite,
|
||||
getCapabilities, getProtectedPaths, getInstallationId, getDiagnosticSources, getRuntimeDiagnostics = () => null, getPerformance = () => null, updates }) {
|
||||
getCapabilities, getProtectedPaths, getInstallationId, getDiagnosticSources, getRuntimeDiagnostics = () => null, getPerformance = () => null, getSystemMetrics = () => null, updates }) {
|
||||
const transfers = createMcpTransfers({ getGrants, getCapabilities, getProtectedPaths, getInstallationId });
|
||||
const sanitize = createMcpSanitizer(loadConfig);
|
||||
const guard = context => {
|
||||
@@ -48,16 +50,33 @@ function createMcpApp({ loadConfig, invoke, invokeGuarded = (_context, channel,
|
||||
};
|
||||
const saveGlobal = async (patch, context) => {
|
||||
canWrite(); guard(context);
|
||||
await invoke('save-global-settings', { ...loadConfig().globalSettings, ...patch });
|
||||
const current = loadConfig().globalSettings;
|
||||
await invoke('save-global-settings', { ...current, ...patch, ...(patch.scramble ? { scramble: { ...current.scramble, ...patch.scramble } } : {}) });
|
||||
await refresh(context);
|
||||
return { saved: true };
|
||||
};
|
||||
const automationAction = async (channel, code, context) => {
|
||||
canWrite(); guard(context);
|
||||
const result = await invoke(channel);
|
||||
if (result?.error || result?.monitorError) throw new McpAccessError(code);
|
||||
return result;
|
||||
};
|
||||
const handlers = {
|
||||
...createMcpFiles({ getGrants, trashFile }),
|
||||
...transfers.handlers,
|
||||
...createMcpDiagnostics({ getSources: getDiagnosticSources, redact: text => sanitize(redactLogText(text, collectSecretValues(loadConfig()))) }),
|
||||
mhu_app_info: () => invoke('get-app-info'),
|
||||
mhu_capabilities: () => {
|
||||
const permissions = getCapabilities?.() || [];
|
||||
const settings = loadConfig().globalSettings;
|
||||
return { permissions, tools: MCP_TOOLS.filter(tool => tool.requiredScopes.every(scope => permissions.includes(scope))).map(tool => ({
|
||||
name: tool.name, readOnly: tool.annotations.readOnlyHint, requiredScopes: tool.requiredScopes,
|
||||
localConfirmation: tool.destructive || requiresMcpConfirmation(tool.name, {}, settings),
|
||||
conditionalConfirmation: tool.name === 'mhu_settings_update'
|
||||
})), boundaries: ['Permissions and directory grants can only be changed locally.', 'Destructive actions require an exact local confirmation; MCP cannot approve it.', 'No arbitrary shell, SQL, mouse/keyboard or screen control.', 'Paused automation is resumed with mhu_automation_resume. A disabled monitor requires mhu_automation_start.'] };
|
||||
},
|
||||
mhu_performance_get: () => getPerformance(),
|
||||
mhu_system_metrics: args => getSystemMetrics(args),
|
||||
mhu_app_state: async (args, context) => ({ ...(await renderer('state', {}, context)), automation: await invoke('automation:get-status') }),
|
||||
mhu_queue_list: (args, context) => renderer('queue-list', args, context),
|
||||
mhu_queue_job_log: async args => page(await invoke('get-job-log', args.jobId), args),
|
||||
@@ -69,8 +88,8 @@ function createMcpApp({ loadConfig, invoke, invokeGuarded = (_context, channel,
|
||||
return renderer('queue-add', { paths: files, hosters: args.hosters }, context);
|
||||
},
|
||||
mhu_queue_start: (args, context) => renderer('queue-start', args, context),
|
||||
mhu_queue_pause: () => invoke('automation:pause-after-active'),
|
||||
mhu_queue_resume: async (args, context) => { guard(context); return invoke('automation:resume'); },
|
||||
mhu_queue_pause: (args, context) => automationAction('automation:pause-after-active', 'AUTOMATION_PAUSE_FAILED', context),
|
||||
mhu_queue_resume: (args, context) => automationAction('automation:resume', 'AUTOMATION_RESUME_FAILED', context),
|
||||
mhu_queue_retry: (args, context) => renderer('queue-retry', args, context),
|
||||
mhu_queue_cancel: (args, context) => renderer('queue-cancel', args, context),
|
||||
mhu_queue_remove: (args, context) => renderer('queue-remove', args, context),
|
||||
@@ -110,7 +129,11 @@ function createMcpApp({ loadConfig, invoke, invokeGuarded = (_context, channel,
|
||||
mhu_accounts_remove: (args, context) => saveAccount(args.accountId, {}, context, true),
|
||||
mhu_accounts_reset_failure: args => { const account = find(args.accountId); return invoke('reset-session-failed-account', { hoster: account.hoster, accountId: args.accountId }); },
|
||||
mhu_settings_get: () => { const config = loadConfig(); const settings = { ...config.globalSettings }; delete settings.pendingQueue; delete settings.uploadRecovery; return { globalSettings: settings, hosterSettings: config.hosterSettings }; },
|
||||
mhu_settings_update: (args, context) => saveGlobal(args, context),
|
||||
mhu_settings_update: async (args, context) => {
|
||||
const result = await saveGlobal(args, context);
|
||||
if (Object.hasOwn(args, 'shutdownAfterFinish')) await invoke('set-shutdown-after-finish', args.shutdownAfterFinish);
|
||||
return result;
|
||||
},
|
||||
mhu_hoster_settings_update: async ({ hoster, ...patch }, context) => {
|
||||
canWrite(); guard(context);
|
||||
const current = loadConfig().hosterSettings;
|
||||
@@ -119,6 +142,8 @@ function createMcpApp({ loadConfig, invoke, invokeGuarded = (_context, channel,
|
||||
return { saved: true };
|
||||
},
|
||||
mhu_automation_status: () => invoke('automation:get-status'),
|
||||
mhu_automation_pause: (args, context) => automationAction('automation:pause-after-active', 'AUTOMATION_PAUSE_FAILED', context),
|
||||
mhu_automation_resume: (args, context) => automationAction('automation:resume', 'AUTOMATION_RESUME_FAILED', context),
|
||||
mhu_automation_update: async ({ rootId, ...patch }, context) => {
|
||||
const folder = await resolveGrantedFile(getGrants(), rootId, '');
|
||||
if (!folder.stat.isDirectory()) throw new McpAccessError('NOT_A_DIRECTORY');
|
||||
@@ -128,9 +153,13 @@ function createMcpApp({ loadConfig, invoke, invokeGuarded = (_context, channel,
|
||||
},
|
||||
mhu_automation_start: async (args, context) => {
|
||||
const settings = loadConfig().globalSettings.folderMonitor;
|
||||
if (!getGrants().some(grant => grant.path === settings.folderPath)) throw new McpAccessError('PATH_NOT_GRANTED');
|
||||
if (settings.paused === true) throw new McpAccessError('AUTOMATION_PAUSED');
|
||||
const normalize = value => process.platform === 'win32' ? path.resolve(value).toLowerCase() : path.resolve(value);
|
||||
if (!settings.folderPath || !getGrants().some(grant => normalize(grant.path) === normalize(settings.folderPath))) throw new McpAccessError('PATH_NOT_GRANTED');
|
||||
await saveGlobal({ folderMonitor: { ...settings, enabled: true } }, context); guard(context);
|
||||
return invoke('folder-monitor:start', { ...settings, enabled: true });
|
||||
const result = await invoke('folder-monitor:start', { ...settings, enabled: true });
|
||||
if (result?.error) throw new McpAccessError('AUTOMATION_START_FAILED');
|
||||
return result;
|
||||
},
|
||||
mhu_automation_stop: async (args, context) => { await saveGlobal({ folderMonitor: { ...loadConfig().globalSettings.folderMonitor, enabled: false } }, context); return invoke('folder-monitor:stop'); },
|
||||
mhu_automation_scan: () => invoke('folder-monitor:test-scan'),
|
||||
@@ -163,6 +192,12 @@ function createMcpApp({ loadConfig, invoke, invokeGuarded = (_context, channel,
|
||||
mhu_update_status: (args, context) => updates.status(args, context),
|
||||
mhu_app_restart: () => invoke('app:restart'),
|
||||
mhu_app_quit: () => invoke('app:quit'),
|
||||
mhu_shutdown_cancel: async (args, context) => {
|
||||
canWrite(); guard(context);
|
||||
await invoke('cancel-shutdown');
|
||||
await saveGlobal({ shutdownAfterFinish: 'nothing' }, context);
|
||||
return { cancelled: true, shutdownAfterFinish: 'nothing' };
|
||||
},
|
||||
mhu_secrets_read: args => { const { password, apiKey } = find(args.accountId); return { accountId: args.accountId, password: password || '', apiKey: apiKey || '' }; }
|
||||
};
|
||||
Object.defineProperty(handlers, 'dispose', { value: () => transfers.dispose() });
|
||||
|
||||
Reference in new issue
Block a user