Skip to content

Commit

Permalink
Enable safe mode for Linux commands
Browse files Browse the repository at this point in the history
Add a new flag to enable safe mode, requiring user confirmation
before executing any Linux command.

Generated by gpt-3.5-turbo
  • Loading branch information
joone committed Mar 22, 2024
1 parent b70f60f commit faea2c6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import * as yargs from "yargs";
import { Loz } from "./loz";
import { DEBUG } from "./constant";
const LOZ_SAFE = process.env.LOZ_SAFE === "true" ? true : false;

const isRunningInMocha = process.env.MOCHA_ENV === "test";

Expand All @@ -23,6 +24,11 @@ const args = yargs
alias: "a",
describe: "Append the model name at the end of the Git commit message.",
},
safe: {
alias: "s",
describe:
"Safe mode requires user confirmation before executing any Linux command.",
},
})
.help()
.parseSync();
Expand Down Expand Up @@ -116,6 +122,8 @@ async function handleInputFromPipe(prompt: any): Promise<void> {

(async () => {
await loz.init();
if (LOZ_SAFE) args.safe = true;
if (args.safe) loz.enableSafe();
await handleLozCommand();
loz.close();
})();
8 changes: 6 additions & 2 deletions src/loz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
} from "./config";
import { Git } from "./git";

const LOZ_SAFE = process.env.LOZ_SAFE === "true" ? true : false;
// Get the path to the home directory
const HOME_PATH = os.homedir() || "";

Expand All @@ -38,6 +37,7 @@ export class Loz {
config: Config = new Config();
git: Git = new Git();
attribution: boolean = false;
safeMode: boolean = false;

constructor() {
this.defaultSettings = {
Expand Down Expand Up @@ -66,6 +66,10 @@ export class Loz {
await this.initLLMfromConfig();
}

public enableSafe(): void {
this.safeMode = true;
}

// load config from JSON file
private async initLLMfromConfig(): Promise<void> {
if (!fs.existsSync(this.configPath)) {
Expand Down Expand Up @@ -362,7 +366,7 @@ export class Loz {
};
this.chatHistoryManager.addChat(promptAndCompleteText);

if (!LOZ_SAFE) {
if (this.safeMode === false) {
try {
await runCommand(linuxCommand);
} catch (error: any) {
Expand Down

0 comments on commit faea2c6

Please sign in to comment.