Feat: Enable YOLO mode for non-interactive execution (#702)
This commit is contained in:
parent
e428707e07
commit
6020c760b5
|
@ -13,11 +13,13 @@ import { readPackageUp } from 'read-package-up';
|
||||||
import { fileURLToPath } from 'node:url';
|
import { fileURLToPath } from 'node:url';
|
||||||
import { dirname } from 'node:path';
|
import { dirname } from 'node:path';
|
||||||
import { sandbox_command, start_sandbox } from './utils/sandbox.js';
|
import { sandbox_command, start_sandbox } from './utils/sandbox.js';
|
||||||
import { loadSettings } from './config/settings.js';
|
import { LoadedSettings, loadSettings } from './config/settings.js';
|
||||||
import { themeManager } from './ui/themes/theme-manager.js';
|
import { themeManager } from './ui/themes/theme-manager.js';
|
||||||
import { getStartupWarnings } from './utils/startupWarnings.js';
|
import { getStartupWarnings } from './utils/startupWarnings.js';
|
||||||
import { runNonInteractive } from './nonInteractiveCli.js';
|
import { runNonInteractive } from './nonInteractiveCli.js';
|
||||||
import {
|
import {
|
||||||
|
ApprovalMode,
|
||||||
|
Config,
|
||||||
EditTool,
|
EditTool,
|
||||||
GlobTool,
|
GlobTool,
|
||||||
GrepTool,
|
GrepTool,
|
||||||
|
@ -114,32 +116,14 @@ async function main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Non-interactive mode handled by runNonInteractive
|
// Non-interactive mode handled by runNonInteractive
|
||||||
let existingCoreTools = config.getCoreTools();
|
const nonInteractiveConfigResult = await loadNonInteractiveConfig(
|
||||||
existingCoreTools = existingCoreTools || [
|
config,
|
||||||
ReadFileTool.Name,
|
settings,
|
||||||
LSTool.Name,
|
|
||||||
GrepTool.Name,
|
|
||||||
GlobTool.Name,
|
|
||||||
EditTool.Name,
|
|
||||||
WriteFileTool.Name,
|
|
||||||
WebFetchTool.Name,
|
|
||||||
WebSearchTool.Name,
|
|
||||||
ReadManyFilesTool.Name,
|
|
||||||
ShellTool.Name,
|
|
||||||
MemoryTool.Name,
|
|
||||||
];
|
|
||||||
const interactiveTools = [ShellTool.Name, EditTool.Name, WriteFileTool.Name];
|
|
||||||
const nonInteractiveTools = existingCoreTools.filter(
|
|
||||||
(tool) => !interactiveTools.includes(tool),
|
|
||||||
);
|
);
|
||||||
const nonInteractiveSettings = {
|
|
||||||
...settings.merged,
|
const nonInteractiveConfig = nonInteractiveConfigResult;
|
||||||
coreTools: nonInteractiveTools,
|
await runNonInteractive(nonInteractiveConfig, input);
|
||||||
};
|
process.exit(0);
|
||||||
const nonInteractiveConfigResult = await loadCliConfig(
|
|
||||||
nonInteractiveSettings,
|
|
||||||
); // Ensure config is reloaded with non-interactive tools
|
|
||||||
await runNonInteractive(nonInteractiveConfigResult.config, input);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Global Unhandled Rejection Handler ---
|
// --- Global Unhandled Rejection Handler ---
|
||||||
|
@ -167,3 +151,41 @@ main().catch((error) => {
|
||||||
}
|
}
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
});
|
});
|
||||||
|
async function loadNonInteractiveConfig(
|
||||||
|
config: Config,
|
||||||
|
settings: LoadedSettings,
|
||||||
|
) {
|
||||||
|
if (config.getApprovalMode() === ApprovalMode.YOLO) {
|
||||||
|
// Since everything is being allowed we can use normal yolo behavior.
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Everything is not allowed, ensure that only read-only tools are configured.
|
||||||
|
|
||||||
|
let existingCoreTools = config.getCoreTools();
|
||||||
|
existingCoreTools = existingCoreTools || [
|
||||||
|
ReadFileTool.Name,
|
||||||
|
LSTool.Name,
|
||||||
|
GrepTool.Name,
|
||||||
|
GlobTool.Name,
|
||||||
|
EditTool.Name,
|
||||||
|
WriteFileTool.Name,
|
||||||
|
WebFetchTool.Name,
|
||||||
|
WebSearchTool.Name,
|
||||||
|
ReadManyFilesTool.Name,
|
||||||
|
ShellTool.Name,
|
||||||
|
MemoryTool.Name,
|
||||||
|
];
|
||||||
|
const interactiveTools = [ShellTool.Name, EditTool.Name, WriteFileTool.Name];
|
||||||
|
const nonInteractiveTools = existingCoreTools.filter(
|
||||||
|
(tool) => !interactiveTools.includes(tool),
|
||||||
|
);
|
||||||
|
const nonInteractiveSettings = {
|
||||||
|
...settings.merged,
|
||||||
|
coreTools: nonInteractiveTools,
|
||||||
|
};
|
||||||
|
const nonInteractiveConfigResult = await loadCliConfig(
|
||||||
|
nonInteractiveSettings,
|
||||||
|
);
|
||||||
|
return nonInteractiveConfigResult.config;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue