@convo-lang/convo-lang-cli
Version:
The language of AI
31 lines • 1.08 kB
JavaScript
import { convoVars, createConvoScopeFunction } from "@convo-lang/convo-lang";
import { execAsync } from "@iyio/node-common";
export const createConvoExec = (confirm) => {
return createConvoScopeFunction(async (scope, exe) => {
if (!scope.paramValues?.length) {
return '';
}
const out = [];
for (let i = 0; i < scope.paramValues.length; i++) {
const cmd = scope.paramValues[i];
if (typeof cmd !== 'string') {
continue;
}
const allow = await confirm(cmd, i);
if (!allow) {
out.push('Access denied');
break;
}
const cwd = exe.getVarEx(convoVars.__cwd, undefined, scope, false);
const r = await execAsync({
cmd,
cwd: (typeof cwd === 'string') ? cwd : undefined,
silent: true,
ignoreErrors: true,
});
out.push(r);
}
return out.join('\n');
});
};
//# sourceMappingURL=convo-exec.js.map