init project
This commit is contained in:
+44
@@ -0,0 +1,44 @@
|
||||
import { config } from '../../config.js';
|
||||
import { runCommand } from '../../lib/runCommand.js';
|
||||
import { errorResult, jsonResult, toErrorMessage } from '../shared.js';
|
||||
import { isAllowedSparkCommand, SPARK_ALLOWED } from './sparkAllowList.js';
|
||||
import { requireCodeIgniter } from './requireCodeIgniter.js';
|
||||
export function registerSparkDiscoverTool(server) {
|
||||
server.registerTool('spark_discover', {
|
||||
title: 'Discover Spark Commands',
|
||||
description: 'Run `php spark list` and return only commands that are on the server allow-list (intersected with SPARK_ALLOWED).',
|
||||
inputSchema: {},
|
||||
}, async () => {
|
||||
try {
|
||||
const ci = requireCodeIgniter();
|
||||
const result = await runCommand('php', ['spark', 'list', '--no-interaction'], {
|
||||
cwd: ci.root,
|
||||
timeoutMs: config.defaultCommandTimeoutMs,
|
||||
});
|
||||
const discovered = new Set();
|
||||
for (const line of result.output.split(/\r?\n/)) {
|
||||
const match = line.match(/^\s*([a-z][\w:-]*)\s+/i);
|
||||
const command = match?.[1];
|
||||
if (command && isAllowedSparkCommand(command)) {
|
||||
discovered.add(command);
|
||||
}
|
||||
}
|
||||
// Also include allow-listed commands even if spark list formatting hid them.
|
||||
for (const allowed of SPARK_ALLOWED) {
|
||||
if (result.output.includes(allowed))
|
||||
discovered.add(allowed);
|
||||
}
|
||||
return jsonResult({
|
||||
exitCode: result.exitCode,
|
||||
failed: result.failed,
|
||||
allowed: [...SPARK_ALLOWED],
|
||||
discovered: [...discovered].sort(),
|
||||
note: 'Only allow-listed spark commands are returned. Use the spark tool to run one.',
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
return errorResult(toErrorMessage(error));
|
||||
}
|
||||
});
|
||||
}
|
||||
//# sourceMappingURL=sparkDiscover.js.map
|
||||
Reference in New Issue
Block a user